Opened 9 years ago
Closed 9 years ago
#27582 closed Cleanup/optimization (fixed)
Allow HStoreField to store null values in key: value pairs
| Reported by: | David Hoffman | Owned by: | |
|---|---|---|---|
| Component: | contrib.postgres | Version: | dev |
| Severity: | Normal | Keywords: | hstore hstorefield |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Overview
PostgreSQL allows values to be either strings or nulls in hstore: https://www.postgresql.org/docs/9.5/static/hstore.html
It appears that the form and model HStoreFields do not support null values. Is this something that should be fixed?
How to reproduce for the form field
>>> from django.contrib.postgres import forms
>>> field = forms.HStoreField()
>>> field.clean('{"a": null}')
{u'a': u'None'}
Expected Behavior
The null has been converted to a string, when it should actually be the None value
How to reproduce for the model field
>>> from django.contrib.postgres.fields import HStoreField
>>> field = HStoreField()
>>> field.clean({'a': None}, None)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/dhoffman/.envs/brain-campaign/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 588, in clean
self.validate(value, model_instance)
File "/Users/dhoffman/.envs/brain-campaign/lib/python2.7/site-packages/django/contrib/postgres/fields/hstore.py", line 36, in validate
params={'key': key},
ValidationError: [u'The value of "a" is not a string.']
Expected Behavior
This should actually be allowed without error.
Change History (7)
comment:1 by , 9 years ago
| Status: | assigned → new |
|---|---|
| Summary: | PostgreSQL form and model HStoreFields do not support null values → PostgreSQL form and model HStoreFields do not support writing null values |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
| Cc: | added |
|---|
Marc, did you make a conscious design decision about this when you first implemented the field?
comment:5 by , 9 years ago
| Cc: | removed |
|---|---|
| Has patch: | set |
| Patch needs improvement: | set |
| Summary: | PostgreSQL form and model HStoreFields do not support writing null values → Allow HStoreField to store null values in key: value pairs |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
comment:6 by , 9 years ago
| Patch needs improvement: | unset |
|---|
Note:
See TracTickets
for help on using tickets.
I have opened a pull request at https://github.com/django/django/pull/7668