python - Saving an object with unsaved related objects -
is there reason why django doesn't provide ability automatically save unsaved related objects?
from docs:
changed in django 1.8.4:
previously, saving object unsaved related objects did not raise error , result in silent data loss. in 1.8-1.8.3, unsaved model instances couldn’t assigned related fields, restriction removed allow easier usage of in-memory models.
i can understand why there a
valueerror: save() prohibited prevent data loss due unsaved related object
instead of saving object default (my guess explicit better implicit), wasn't able find aforementioned feature request.
from ticket lead change
i prefer failing , loudly, raising exception when unsaved object assigned related field.
i listen argument trying re-fetch pk cached related instance in save(), feels action-at-a-distance: actual problem happened earlier.
automatically saving related objects magic; i'm sure considered unexpected , undesirable in circumstances.
my interpretation developers of django not want people habit of things being automatically saved because lead problems @ different point in time. explicit save of each object ensures developers aware of being saved, , reduces accidental changes line of code breaking functionality.
Comments
Post a Comment