Opened 8 years ago
Last modified 5 years ago
#26819 closed Bug
Using a ArrayField on Meta.unique_together throws "unhashable type: 'list'" on validate_unique method — at Version 11
Reported by: | Gleber Diniz | Owned by: | PREMANAND |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Change History (5)
comment:1 by , 8 years ago
Component: | Uncategorized → contrib.postgres |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:9 by , 8 years ago
comment:10 by , 8 years ago
Not sure without looking into the details myself, but it might be better if the validate_unique()
method took care of casting as needed since changing the return value of to_python()
could be backwards-incompatible.
comment:11 by , 8 years ago
Description: | modified (diff) |
---|
As you mentioned, implemented fix in validate_unique() method. The above code fixes the issue and all the unit tests got passed.
The only problem is Im not sure how to write the test case. It needs to be simulated as if a user creates a form in the html page. Do you have any pointers for testing similar condition?
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else tuple(d) if type(d) is list else d for d in row_data)
This issue occurs as the array item is stored in the lists and there is a mis-match while comparison.
The arrayitem is stored in row_data as list and list are not hashable as the error says.
if row_data in seen_data:
This issue can be fixed by changing this line ie; return a tuple instead of list.
https://github.com/PREM1980/django/blob/master/django/contrib/postgres/forms/array.py#L56
Please review and provide your comments.