diff options
| author | Andrea Grandi <a.grandi@gmail.com> | 2015-05-24 15:56:48 +0100 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2015-05-24 17:32:16 +0200 |
| commit | 43b2d88a5b9cfb151ccf7ac861f2750e70c0e2c4 (patch) | |
| tree | 005355dd476cfa4cbde0bf52a043fccc15cb0335 | |
| parent | 9ef2615d4968ed52dbd88a19f03746a2f16c7511 (diff) | |
Fixed #24844 -- Corrected has_changed implementation for HStoreField.
| -rw-r--r-- | django/contrib/postgres/forms/hstore.py | 10 | ||||
| -rw-r--r-- | django/db/backends/postgresql_psycopg2/base.py | 1 | ||||
| -rw-r--r-- | tests/postgres_tests/test_hstore.py | 6 |
3 files changed, 17 insertions, 0 deletions
diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py index 2c564ea53c..a138093e90 100644 --- a/django/contrib/postgres/forms/hstore.py +++ b/django/contrib/postgres/forms/hstore.py @@ -34,3 +34,13 @@ class HStoreField(forms.CharField): for key, val in value.items(): value[key] = six.text_type(val) return value + + def has_changed(self, initial, data): + """ + Return True if data differs from initial. + """ + # For purposes of seeing whether something has changed, None is + # the same as an empty dict, if the data or initial value we get + # is None, replace it w/ {}. + initial_value = self.to_python(initial) + return super(forms.HStoreField, self).has_changed(initial_value, data) diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index af616e48c4..6c0794d92d 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -199,6 +199,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): if conn_timezone_name != self.timezone_name: cursor = self.connection.cursor() try: + print "UPS" cursor.execute(self.ops.set_time_zone_sql(), [self.timezone_name]) finally: cursor.close() diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py index e63eda46b9..9569711b3d 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -178,6 +178,12 @@ class TestFormField(PostgresSQLTestCase): form_field = model_field.formfield() self.assertIsInstance(form_field, forms.HStoreField) + def test_empty_field_has_not_changed(self): + class HStoreFormTest(forms.Form): + f1 = HStoreField() + form_w_hstore = HStoreFormTest() + self.assertFalse(form_w_hstore.has_changed()) + class TestValidator(PostgresSQLTestCase): |
