diff options
| author | Simon Charette <charette.s@gmail.com> | 2020-10-05 09:13:14 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-05 20:42:46 +0200 |
| commit | 4c675523bd3e45906bf6736444c65b066e25208c (patch) | |
| tree | 583694f65a6eec7dc159863f253541e07d0f5d09 /django/utils/hashable.py | |
| parent | 981a3426cf2f54f5282e79fb7f47726998c87cb2 (diff) | |
Refs #29838, Refs #28507 -- Made make_hashable() ignore key order.
Diffstat (limited to 'django/utils/hashable.py')
| -rw-r--r-- | django/utils/hashable.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/django/utils/hashable.py b/django/utils/hashable.py index 0bef5b003d..7d137ccc2f 100644 --- a/django/utils/hashable.py +++ b/django/utils/hashable.py @@ -2,10 +2,15 @@ from django.utils.itercompat import is_iterable def make_hashable(value): + """ + Attempt to make value hashable or raise a TypeError if it fails. + + The returned value should generate the same hash for equal values. + """ if isinstance(value, dict): return tuple([ (key, make_hashable(nested_value)) - for key, nested_value in value.items() + for key, nested_value in sorted(value.items()) ]) # Try hash to avoid converting a hashable iterable (e.g. string, frozenset) # to a tuple. |
