mirror of
https://github.com/django/django.git
synced 2025-10-04 07:46:37 +00:00
Fixed ModelState breaking when unique_together has unhashable elements.
This commit is contained in:
parent
54d9e3ccf6
commit
19e4374971
3 changed files with 10 additions and 6 deletions
|
@ -32,10 +32,13 @@ def normalize_unique_together(unique_together):
|
|||
tuple of two strings. Normalize it to a tuple of tuples, so that
|
||||
calling code can uniformly expect that.
|
||||
"""
|
||||
unique_together = tuple(unique_together)
|
||||
if unique_together and not isinstance(unique_together[0], (tuple, list)):
|
||||
if not unique_together:
|
||||
return ()
|
||||
first_element = next(iter(unique_together))
|
||||
if not isinstance(first_element, (tuple, list)):
|
||||
unique_together = (unique_together,)
|
||||
return unique_together
|
||||
# Normalize everything to tuples
|
||||
return tuple(tuple(ut) for ut in unique_together)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue