summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDavid Hoffman <me@davidhoffman.ca>2016-12-08 19:17:02 -0500
committerTim Graham <timograham@gmail.com>2016-12-15 10:35:44 -0500
commitbf84d042e0bba636fe2199051fe25e96d89865da (patch)
tree119470db1a6f0f6d5de6b66f71929c92a6a4e97f /django
parent9524fd9133e47fa90846904f81fe91c72f331e56 (diff)
Fixed #27582 -- Allowed HStoreField to store null values.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/postgres/fields/hstore.py6
-rw-r--r--django/contrib/postgres/forms/hstore.py4
2 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/postgres/fields/hstore.py b/django/contrib/postgres/fields/hstore.py
index 76f41886a9..605deaf62c 100644
--- a/django/contrib/postgres/fields/hstore.py
+++ b/django/contrib/postgres/fields/hstore.py
@@ -13,9 +13,9 @@ __all__ = ['HStoreField']
class HStoreField(Field):
empty_strings_allowed = False
- description = _('Map of strings to strings')
+ description = _('Map of strings to strings/nulls')
default_error_messages = {
- 'not_a_string': _('The value of "%(key)s" is not a string.'),
+ 'not_a_string': _('The value of "%(key)s" is not a string or null.'),
}
def db_type(self, connection):
@@ -30,7 +30,7 @@ class HStoreField(Field):
def validate(self, value, model_instance):
super(HStoreField, self).validate(value, model_instance)
for key, val in value.items():
- if not isinstance(val, six.string_types):
+ if not isinstance(val, six.string_types) and val is not None:
raise exceptions.ValidationError(
self.error_messages['not_a_string'],
code='not_a_string',
diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py
index 4ed99d1fda..76d362999d 100644
--- a/django/contrib/postgres/forms/hstore.py
+++ b/django/contrib/postgres/forms/hstore.py
@@ -43,7 +43,9 @@ class HStoreField(forms.CharField):
# Cast everything to strings for ease.
for key, val in value.items():
- value[key] = six.text_type(val)
+ if val is not None:
+ val = six.text_type(val)
+ value[key] = val
return value
def has_changed(self, initial, data):