﻿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
18864	Django models __eq__ and __hash__ treat all unsaved model instances as identical	fengb	nobody	"When a model instance is still new and unsaved, it has no primary key.

Both __eq__ and __hash__ rely solely on _get_pk_val(), which means all unsaved model instances are treated as though they are identical.

>>> b1 = models.Base()
>>> b2 = models.Base()
>>> b1 == b2
True
>>> hash(b1) == hash(b2)
True

For integrity, we should add a check for Python object identity since if both instances are saved, they will end up with different PKs.

For hashing, we can use the default Python hashing to prevent large collisions based on hash(None).  We would also need to cache the hash so that hash(instance) will be the same both before save and after save such that:
>>> b = models.Base()
>>> s = set()
>>> s.add(b)
>>> b.save()
>>> b in set
True

This last case actually has an edge case that I'm not sure is solvable.
>>> b = models.Base.object.get(id=b.id)
>>> b in set
False"	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed		jdunck@… Ben Davis	Accepted	0	0	0	0	0	0
