#10811: Assigning unsaved model to a ForeignKey leads to silent failures
-------------------------------------+-------------------------------------
Reporter: Glenn | Owner:
| anubhav9042
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by mvantellingen):
Replying to [comment:41 akaariai]:
> I must say I believe doing the check at save() time is better than
disallowing assignment completely. This should result in the same data-
loss-preventation effect, while giving better backwards compatibility for
users.
>
> The check in save() would essentially be "if 'fk' in self.__dict__ and
self.fk.id is None -> raise Error" (with suitable replacements to get the
from and to fields dynamically). I believe this is safe to backpatch to
1.8, as currently assigning anything with pk = None to fk will raise an
error. So, there shouldn't be any code where the check is True in released
1.8 versions.
I agree that moving the check to the save() method seems the best
solution. This change really caused our unittests to run much slower since
now we need to create objects in the database to test properties unrelated
to the fk's. How can we get this in 1.9 ?
--
Ticket URL: <https://code.djangoproject.com/ticket/10811#comment:42>
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/063.2b6810da99e9fd1e331e79980fa558d4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.