#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 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/10811#comment:41>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.d30c72ef173cf62bc821294eea8a7798%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to