#28147: Saving parent object after setting on child leads to unexpected data
loss
-------------------------------------+-------------------------------------
Reporter: Erwin Junge | Owner: robinh00d
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by robinh00d):
> I went through the PR proposed here and I noticed the .pk usage was
probably missing to_field usages.
In the context of this ticket,
If there was a case where a foreign key had a custom `to_field`, current
behavior will depend on the DB to raise an exception if the value is not
assigned OR assigned to a non-existing reference.
Similarly to the usage of `.pk`, we can potentially add logic to check if
the value has been assigned or not. And if it hasn't been assigned, we can
raise the `save() prohibited to prevent data loss due to...` exception
message. The advantage of this is that we're raising the exception in code
which means no unnecessary DB call is required.
In the case where the value is assigned, but to a non-existing reference,
I guess we really have no other choice but to let the DB handle it.
Whether or not a patch to handle missing `to_field` is required is beyond
me.
I agree with adding the regression tests, I will add it in later when I'm
free :)
--
Ticket URL: <https://code.djangoproject.com/ticket/28147#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.80bd5099c391064edc6eca7ab1f9ea47%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.