[Django] #27582: PostgreSQL form and model HStoreFields do not support null values

36 views
Skip to first unread message

Django

unread,
Dec 8, 2016, 7:14:46 PM12/8/16
to django-...@googlegroups.com
#27582: PostgreSQL form and model HStoreFields do not support null values
-------------------------------------+-------------------------------------
Reporter: David | Owner: (none)
Hoffman |
Type: Bug | Status: assigned
Component: | Version: master
contrib.postgres |
Severity: Normal | Keywords: hstore hstorefield
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
= 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27582>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 8, 2016, 7:31:05 PM12/8/16
to django-...@googlegroups.com
#27582: PostgreSQL form and model HStoreFields do not support writing null values
------------------------------------+--------------------------------------
Reporter: David Hoffman | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by David Hoffman):

* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:1>

Django

unread,
Dec 8, 2016, 7:43:23 PM12/8/16
to django-...@googlegroups.com
#27582: PostgreSQL form and model HStoreFields do not support writing null values
------------------------------------+--------------------------------------
Reporter: David Hoffman | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

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>

Django

unread,
Dec 9, 2016, 9:06:16 AM12/9/16
to django-...@googlegroups.com
#27582: PostgreSQL form and model HStoreFields do not support writing null values
------------------------------------+--------------------------------------
Reporter: David Hoffman | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Dec 9, 2016, 10:00:46 AM12/9/16
to django-...@googlegroups.com
#27582: PostgreSQL form and model HStoreFields do not support writing null values
------------------------------------+--------------------------------------
Reporter: David Hoffman | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Marc Tamlyn):

Not that I recall. This use case should be valid.

--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:4>

Django

unread,
Dec 9, 2016, 11:01:08 AM12/9/16
to django-...@googlegroups.com
#27582: Allow HStoreField to store null values in key: value pairs
--------------------------------------+------------------------------------

Reporter: David Hoffman | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Dec 12, 2016, 12:42:36 PM12/12/16
to django-...@googlegroups.com
#27582: Allow HStoreField to store null values in key: value pairs
--------------------------------------+------------------------------------
Reporter: David Hoffman | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: hstore hstorefield | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27582#comment:6>

Django

unread,
Dec 15, 2016, 11:05:23 AM12/15/16
to django-...@googlegroups.com
#27582: Allow HStoreField to store null values in key: value pairs
-------------------------------------+-------------------------------------
Reporter: David Hoffman | Owner: Tim
Type: | Graham <timograham@…>
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: master
Severity: Normal | Resolution: fixed
Keywords: hstore hstorefield | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages