Changes between Initial Version and Version 1 of Ticket #30651


Ignore:
Timestamp:
Jul 21, 2019, 11:30:54 AM (5 years ago)
Author:
Elizabeth Uselton
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30651 – Description

    initial v1  
    1 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.
     1`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.
    22
    3 https://github.com/django/django/blob/master/django/db/models/base.py#L526
     3`https://github.com/django/django/blob/master/django/db/models/base.py#L526`
    44
    5 According to the Python 3 data model reference, a __eq__ should return NotImplemented
    6 https://docs.python.org/3/reference/datamodel.html#object.__eq__
    7 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.
     5According to the Python 3 data model reference, a `__eq__` should return NotImplemented
     6`https://docs.python.org/3/reference/datamodel.html#object.__eq__`
     7If `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.
    88
    99This may seem like a relatively innocuous difference, but it can cause some nasty bugs. The most obvious is that for testing,
    10 <A Django Model> == mock.ANY returns False, since by not returning NotImplemented it never even looks at the overridden __eq__ on ANY.
     10<A Django Model> == mock.ANY returns False, since by not returning NotImplemented it never even looks at the overridden `__eq__` on ANY.
Back to Top