﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23592	Django 1.5 Proxy equality and Caching of related instances	Cisco Guillaume	nobody	"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 = OrderedPerson()
}}}


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"	Bug	closed	Database layer (models, ORM)	1.5	Normal	wontfix	proxy equality		Unreviewed	0	0	0	0	0	0
