Prevent setting nullable relations on unsaved objects
|Reported by:||Vlastimil Zíma||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.6|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Assume you have models
UndergroundBar with nullable one-to-one relation to the place, as in
one_to_one_regress tests models.
Since Django 1.6 the one-to-one relation on unsaved objects became asymmetric. You could set one-to-one relation, but not the reverse one-to-one relation, even though setting forward relation sets the cache for reverse relation.
place = Place() bar = UndergroundBar() place.undergroundbar = bar # Raises error # But bar.place = place place.undergroundbar # Returns 'bar'
I attach patch with fix and modification of regression test
test_set_reverse_on_unsaved_object. I have not found any other problems which should prevent relations between unsaved objects, especially because they can be created anyway.
Change History (5)
comment:1 Changed 3 years ago by
|Summary:||Enable one-to-one reverse cache on unsaved objects → Prevent setting nullable relations on unsaved objects|
|Triage Stage:||Unreviewed → Accepted|