#35965: Let GenericForeignKeys behave like a ForeignKey w.r.t. unsaved objects
-------------------------------------+-------------------------------------
     Reporter:  Willem Van Onsem     |                     Type:  Bug
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  5.1                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 As mentioned on [https://stackoverflow.com/q/79244238/67579
 StackOverflow], a `ForeignKey` can still save an object if the object was
 not saved when setting the model object, like:

 {{{
 one = Model_One()
 two = Model_Two(model_one=one)
 one.save()
 two.save()
 }}}

 But this is not the case for a `GenericForeignKey` with:

 {{{
 one = Model_One()
 two = Model_With_GFK(content_object=one)
 one.save()
 two.save()
 }}}

 This is because the `content_object` *immediately* sets the content type
 field and the foreign key field when setting the object, and then leaves
 is that way.

 Perhaps overkill, but it might be worth to do the same for a `ForeignKey`
 and thus check if the object has been given `.pk`, and if so, set the
 foreign key field.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35965>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019387c41e6d-4984e776-d6d4-4a99-94c9-595f176e5afd-000000%40eu-central-1.amazonses.com.

Reply via email to