forms.HStoreField crashes on an empty JSON array
Problem: Submitting a JSON array ([]
) into the default Django admin form for HStoreField (django.contrib.postgres.fields.HStoreField
) throws an error.
There is some incorrect logic with the validation where if anything but a dict is passed to the to_python method, the field tries to json.load() the data and then iterate over it with value.items(). Lists don't implement this method, and so we an AttibuteError is raised.
To reproduce:
- Add an HStoreField to a model, and register that model with Django Admin.
- In the model admin edit view, insert a list into the textfield
- Submit.
Traceback: https://dpaste.de/bjUh
Change History
(12)
Owner: |
set to Brad Melin
|
Status: |
new → assigned
|
Triage Stage: |
Unreviewed → Accepted
|
Summary: |
When adding a JSON array to the Admin HStoreField widget, Django raises an AttibuteError → forms.HStoreField crashes on an empty JSON array
|
Patch needs improvement: |
set
|
Severity: |
Normal → Release blocker
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
I suppose a
ValidationError
should be raised instead.