mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed model.__eq__ and __hash__ for no pk value cases
The __eq__ method now considers two instances without primary key value equal only when they have same id(). The __hash__ method raises TypeError for no primary key case. Fixed #18864, fixed #18250 Thanks to Tim Graham for docs review.
This commit is contained in:
@@ -199,6 +199,14 @@ Miscellaneous
|
||||
equal when primary keys match. Previously only instances of exact same
|
||||
class were considered equal on primary key match.
|
||||
|
||||
* The :meth:`django.db.models.Model.__eq__` method has changed such that
|
||||
two ``Model`` instances without primary key values won't be considered
|
||||
equal (unless they are the same instance).
|
||||
|
||||
* The :meth:`django.db.models.Model.__hash__` will now raise ``TypeError``
|
||||
when called on an instance without a primary key value. This is done to
|
||||
avoid mutable ``__hash__`` values in containers.
|
||||
|
||||
Features deprecated in 1.7
|
||||
==========================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user