#30651: Model.__eq__ never returns NotImplemented
-------------------------------------+-------------------------------------
               Reporter:  Elizabeth  |          Owner:  Elizabeth Uselton
  Uselton                            |
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Model.__eq__ never returns NotImplemented if it encounters an object it
 doesn't know how to compare against. Instead, if the object it is
 comparing to is not a Django Model, it automatically returns False.

 https://github.com/django/django/blob/master/django/db/models/base.py#L526

 According to the Python 3 data model reference, a __eq__ should return
 NotImplemented
 https://docs.python.org/3/reference/datamodel.html#object.__eq__
 If a.__eq__(b) returns NotImplemented, then b.__eq__(a) will be tried. If
 both return NotImplemented, then an is check is performed, and if that
 fails it returns False.

 This may seem like a relatively innocuous difference, but it can cause
 some nasty bugs. The most obvious is that for testing,
 <A Django Model> == mock.ANY returns False, since by not returning
 NotImplemented it never even looks at the overridden __eq__ on ANY.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30651>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/053.f5efe8ecf1b1216cc5293f9268b76a4e%40djangoproject.com.

Reply via email to