﻿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
30651	__eq__ should return NotImplemented when equality cannot be checked.	Elizabeth Uselton	Elizabeth Uselton	"`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."	Cleanup/optimization	closed	Core (Other)	dev	Normal	fixed		Elizabeth Uselton	Ready for checkin	1	0	0	0	0	0
