You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting is nullable but its generic get type parameter is not optional for fields with derived ForeignKey field types.
Given my main model uses a "name" as primary key, I'd like to use _name instead of _id as attname and dbcolum suffix, and I think I can only overwrite dbcolumn in a fields constructor (not the attname).
Demo code:
class ForeignNameKey(models.ForeignKey):
def get_attname(self) -> str:
return '%s_name' % self.name
class Domain(models.Model):
name = models.CharField(unique=True, max_length=255, blank=False, primary_key=True)
class Foo(models.Model):
domain = ForeignNameKey(
Domain,
on_delete=models.RESTRICT,
null=True,
)
-> error: ForeignNameKey is nullable but its generic get type parameter is not optional
I tried understanding what the code from #2048 does, but couldn't figure out why it works with models.ForeignKey and not with my derived class. Also the error message is completely useless - I have no idea how to "fix" it (also unclear what is wrong; I don't think anything is actually wrong).
System information
OS: debian bookworm
python version: 3.11.2
django version: 5.1.2
mypy version: 1.11.2
django-stubs version: 5.1.0
django-stubs-ext version: 5.1.0
The text was updated successfully, but these errors were encountered:
Hi.
I'm getting
is nullable but its generic get type parameter is not optional
for fields with derivedForeignKey
field types.Given my main model uses a "name" as primary key, I'd like to use
_name
instead of_id
as attname and dbcolum suffix, and I think I can only overwrite dbcolumn in a fields constructor (not the attname).Demo code:
->
error: ForeignNameKey is nullable but its generic get type parameter is not optional
I tried understanding what the code from #2048 does, but couldn't figure out why it works with
models.ForeignKey
and not with my derived class. Also the error message is completely useless - I have no idea how to "fix" it (also unclear what is wrong; I don't think anything is actually wrong).System information
python
version: 3.11.2django
version: 5.1.2mypy
version: 1.11.2django-stubs
version: 5.1.0django-stubs-ext
version: 5.1.0The text was updated successfully, but these errors were encountered: