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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27582>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:1>
Comment (by David Hoffman):
I have opened a pull request at https://github.com/django/django/pull/7668
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:2>
* cc: Marc Tamlyn (added)
Comment:
Marc, did you make a conscious design decision about this when you first
implemented the field?
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:3>
Comment (by Marc Tamlyn):
Not that I recall. This use case should be valid.
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:4>
* cc: Marc Tamlyn (removed)
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:6>
* status: new => closed
* owner: (none) => Tim Graham <timograham@…>
* resolution: => fixed
Comment:
In [changeset:"bf84d042e0bba636fe2199051fe25e96d89865da" bf84d04]:
{{{
#!CommitTicketReference repository=""
revision="bf84d042e0bba636fe2199051fe25e96d89865da"
Fixed #27582 -- Allowed HStoreField to store null values.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:7>