#26819: Using a ArrayField on Meta.unique_together throws "unhashable type:
'list'"
on validate_unique method
----------------------------------+-------------------------------------
Reporter: Gleber Diniz | Owner: PREMANAND
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------
Comment (by Meiyer):
This happens only for Inline admin models (only `validate_unique()` of
`BaseModelFormSet` contains the problematic code).
This is not limited to `ArrayField`; any custom field may be affected. In
our case, the `phonenumber_field.modelfields.PhoneNumberField` is causing
the error `unhashable type: 'PhoneNumber'`. Since Django documentation
does not mandate that custom fields are hashable (i.e., define the
`__hash__()` method), I suppose that most of the existing non-builtin
fields are affected.
Looks like the solution is either to keep `seen_data` as a `set()` and
rely on some property of the field (unreliable and error-prone, see sample
code below), or give up `set()` and manually implement removal of
duplicates.
{{{
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else
d if d.__hash__ is not None else
d.__repr__()
for d in row_data)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26819#comment:15>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.52f879cf66990e7b9a622e2848cb626c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.