#23592: Django 1.5 Proxy equality and Caching of related instances
----------------------------------------------+----------------------------
     Reporter:  GuillaumeCisco                |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.5
     Severity:  Normal                        |   Keywords:  proxy equality
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+----------------------------
 Hello there :)

 This is the first time I write a ticket regarding Django code, so I'll try
 to be as concise as possible.

 When upgrading to django 1.5 for our company project, we ran in an
 unexpected behaviour.

 We use a proxy model and for our needs, we use equality operator in the
 code.
 Let's say I have a Person Model and a OrderedPerson Model which is a proxy
 of the Person Model.


 {{{
 a = Person()
 b = OrderedParson()
 }}}


 We have two equal objects (id and __dict__ are similar) so b == a should
 be equal to True (correct in Django 1.4).
 However we get:

 b == a <- False
 Due to this commit posted in Django 1.5 version:
 
https://github.com/django/django/commit/056ace0f395a58eeac03da9f9ee7e3872e1e407b
 File django/db/models/query.py Lines '''327-336'''

 In reality, it is far more complex, because we have a test like:

 {{{
 def __setattr__(self, name, value):
     toto = getattr(self, name, None) == value
     # some code with toto variable
 }}}


 I found this commit solve the problem regarding proxy equality in Django
 1.7:
 
https://github.com/django/django/commit/4668c142dce77c6f29fb75532c1acfa1b2d322ff
 #diff-507b415116b409afa4f723e41a759a9eR338
 File django/db/models/base.py Lines '''462-464'''

 So we use it for our proxy models in Django 1.5

 I think it could be very useful to add this piece of code, for versions
 from Django 1.5.

 Cheers.

 PS: I used these sources for understanding the origin of this "bug":
 http://stackoverflow.com/questions/390250/elegant-ways-to-support-
 equivalence-equality-in-python-classes
 http://stackoverflow.com/questions/3588776/how-is-eq-handled-in-python-
 and-in-what-order/12984987#12984987
 https://docs.djangoproject.com/en/1.7/topics/db/models/#proxy-models

--
Ticket URL: <https://code.djangoproject.com/ticket/23592>
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/057.9be60169010e1e9aece7f953b64fe0c3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to