Inherited model fails to handle blank field properly
|Reported by:||yuval_a||Owned by:|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I just opened a stack overflow question about this, but after digging a bit this is starting to look like a bug.
Take two simple models with inheritance:
class A(models.Model): a = models.IntegerField(blank=True) class B(A): b = models.IntegerField(blank=True)
And then in runtime:
>>> A() <A: A object> >>> B() Traceback (most recent call last): File "<console>", line 1, in <module> File "django/db/models/base.py", line 357, in __init__ setattr(self, field.attname, val) File "django/db/models/fields/related.py", line 271, in __set__ (instance._meta.object_name, self.related.get_accessor_name())) ValueError: Cannot assign None: "B.b" does not allow null values.
There should be absolutely no reason why A() is properly created, while B() should fail.
Change History (7)
comment:1 Changed 3 years ago by yuval_a
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:5 Changed 12 months ago by navi7
- Owner changed from nobody to navi7
- Status changed from new to assigned