Prevent setting nullable relations on unsaved objects
|Reported by:||vzima||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 Place and 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)
Changed 21 months ago by vzima
comment:1 Changed 21 months ago by aaugustin
- Has patch unset
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from Enable one-to-one reverse cache on unsaved objects to Prevent setting nullable relations on unsaved objects
- Triage Stage changed from Unreviewed to Accepted