#35488: BaseModelFormSet.validate_unique() raises TypeError unhashable type:
'dict'
for JSONFields in a UniqueConstraint
-------------------------------------+-------------------------------------
Reporter: Hanne Moa | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 5.0
Severity: Normal | Resolution:
Keywords: JSONField, unique, | Triage Stage: Accepted
formset, json, hashable |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
I think this has little to do with #23964 (which focuses on
`UniqueConstraint`) and is more of an analogous to #26819 (which was for
another field using non-hashable types) but for `JSONField`.
{{{#!diff
diff --git a/django/forms/models.py b/django/forms/models.py
index 4cda4e534e..42feeac5c2 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -23,6 +23,7 @@
SelectMultiple,
)
from django.utils.choices import BaseChoiceIterator
+from django.utils.hashable import make_hashable
from django.utils.text import capfirst, get_text_list
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
@@ -835,7 +836,7 @@ def validate_unique(self):
d._get_pk_val()
if hasattr(d, "_get_pk_val")
# Prevent "unhashable type: list" errors later
on.
- else tuple(d) if isinstance(d, list) else d
+ else make_hashable(d)
)
for d in row_data
)
}}}
The problem IMO is that 06a11ef6ecf324db0a1530b8cca727883698f442 focused
on one type on unhashable value instead of the generic problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/35488#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018fc4c21059-b03f9a0f-bb83-42b0-94ca-496f0d522139-000000%40eu-central-1.amazonses.com.