#28856: GenericForeignKey attributes create new instances on every access
-------------------------------------+-------------------------------------
     Reporter:  Morgan Wahl          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:                       |                  Version:  1.10
  contrib.contenttypes               |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 I'm pretty sure this is the expected behavior from `refresh_from_db()`,
 refreshing any relationship should create a new instance as
 `ref.refresh_from_db()` should roughly translate to `ref =
 Ref.objects.get(pk=ref.pk)` while preserving `ref` identity.

 e.g. foreign key relationships have always worked this way

 {{{#!python
 >> obj_type = ref.obj_type
 >> ref.refresh_from_db()
 >> ref.obj_type is obj_type
 False
 }}}

 b9f8635f58ad743995cad2081b3dc395e55761e5 just made this consistent for
 generic foreign key which wouldn't be refreshed before it landed. This was
 a problem because if either `ref.obj_type` or `ref.obj_id` had changed
 when `refresh_from_db()` was called  then `ref.obj` would point to a
 different object that the one referenced by `ref.obj_type` and
 `ref.obj_id`.

 Django's ORM doesn't maintain an identity mapping of object, as opposed to
 SQL Alchemy for example, so you shouldn't expect refreshed instances to
 share their identity.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28856#comment:3>
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.9c709b6f96d0738c3adca14ad6b058b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to