mirror of
https://github.com/django/django.git
synced 2025-09-05 16:49:15 +00:00
Fixed #33441 -- Restored immutability of models.Field.__hash__().
Regression in 502e75f9ed5476ffe8229109acf0c23999d4b533.
This commit is contained in:
parent
652c68ffee
commit
fdfa97fb16
@ -542,11 +542,7 @@ class Field(RegisterLookupMixin):
|
|||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((
|
return hash(self.creation_counter)
|
||||||
self.creation_counter,
|
|
||||||
self.model._meta.app_label if hasattr(self, 'model') else None,
|
|
||||||
self.model._meta.model_name if hasattr(self, 'model') else None,
|
|
||||||
))
|
|
||||||
|
|
||||||
def __deepcopy__(self, memodict):
|
def __deepcopy__(self, memodict):
|
||||||
# We don't have to deepcopy very much here, since most things are not
|
# We don't have to deepcopy very much here, since most things are not
|
||||||
|
@ -128,9 +128,14 @@ class BasicFieldTests(SimpleTestCase):
|
|||||||
self.assertLess(abstract_model_field, inherit2_model_field)
|
self.assertLess(abstract_model_field, inherit2_model_field)
|
||||||
self.assertLess(inherit1_model_field, inherit2_model_field)
|
self.assertLess(inherit1_model_field, inherit2_model_field)
|
||||||
|
|
||||||
self.assertNotEqual(hash(abstract_model_field), hash(inherit1_model_field))
|
def test_hash_immutability(self):
|
||||||
self.assertNotEqual(hash(abstract_model_field), hash(inherit2_model_field))
|
field = models.IntegerField()
|
||||||
self.assertNotEqual(hash(inherit1_model_field), hash(inherit2_model_field))
|
field_hash = hash(field)
|
||||||
|
|
||||||
|
class MyModel(models.Model):
|
||||||
|
rank = field
|
||||||
|
|
||||||
|
self.assertEqual(field_hash, hash(field))
|
||||||
|
|
||||||
|
|
||||||
class ChoicesTests(SimpleTestCase):
|
class ChoicesTests(SimpleTestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user