Model equality in inheritance cases

53 views
Skip to first unread message

Anssi Kääriäinen

unread,
Jul 16, 2012, 3:07:02 PM7/16/12
to Django developers
I was looking through some old tickets, and spotted a case which I had
worked on some time ago. The case is about model instance equality in
different inheritance situations. There are three different cases to
consider (assuming primary keys match):
- should a proxy model be equal to its proxy parent?
- should a inherited model be equal to its parent instance?
- what to do in model multi-inheritance cases.

My take is that proxy models should be equal to their parent
instances, otherwise inherited models should not equal their parent
instances. The reasons for this are backwards compatibility,
performance and achieving correctness for all cases.

I won't go into details of what kind of problems multitable multi-
inheritance causes for achieving correctness. Suffice to say that it
is possible to construct cases where is it very hard to tell if two
models should be equal or not. Refer to ticket #16458 for more
details.

The backwards compatibility issue is in my opinion enough to say "no"
to the multitable-inheritance case. Django has one use in admin which
downright breaks when child models are equal to their parent models.
User code could have similar problems, too.

Writing a patch for proxy model equality is straightforward. Writing a
patch which takes all the corner cases of multitable multi-inheritance
in account is not trivial at all.

So, I propose to go forward with proxy model equality. Doing something
to this long standing issue would be welcome in any case.

For more dirty details, see ticket #16458. Tickets #11892 and #14492
are related.

- Anssi

Daniel Sokolowski

unread,
Jul 16, 2012, 5:44:06 PM7/16/12
to Django developers
I would also throw this ticket into the mix -
https://code.djangoproject.com/ticket/11154, it's related and has bit me in
the past.
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to
django-develop...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.


Daniel Sokolowski
Web Engineer
Danols Web Engineering
http://webdesign.danols.com/

charettes

unread,
Jul 16, 2012, 6:18:26 PM7/16/12
to django-d...@googlegroups.com
#11154 is really about another issue; it has nothing to do with model equality.

I'll try to submit a new patch with a release not in the next days as requested by anssi.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to
django-developers+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages