diff options
| author | Joshua Phillips <jphillips@imap.cc> | 2016-04-29 11:44:56 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-29 10:11:49 -0400 |
| commit | 4681d65048ca2553895e10c2c492997b0a78ffba (patch) | |
| tree | cc533591f58a7c2db3dba2337dd6f79223bffa97 | |
| parent | 2f698cd9916cb3d64932248c7114049e02b74fb3 (diff) | |
Fixed #26557 -- Converted empty strings to None when saving GenericIPAddressField.
| -rw-r--r-- | django/db/backends/base/operations.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.9.6.txt | 3 | ||||
| -rw-r--r-- | tests/model_fields/test_genericipaddressfield.py | 8 |
3 files changed, 12 insertions, 1 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 6cd466411a..fe21fd6e58 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -499,7 +499,7 @@ class BaseDatabaseOperations(object): Transforms a string representation of an IP address into the expected type for the backend driver. """ - return value + return value or None def year_lookup_bounds_for_date_field(self, value): """ diff --git a/docs/releases/1.9.6.txt b/docs/releases/1.9.6.txt index 7e3f6aed6a..769d04945a 100644 --- a/docs/releases/1.9.6.txt +++ b/docs/releases/1.9.6.txt @@ -24,3 +24,6 @@ Bugfixes * Fixed a regression causing the cached template loader to crash when using template names starting with a dash (:ticket:`26536`). + +* Restored conversion of an empty string to null when saving values of + ``GenericIPAddressField`` on SQLite and MySQL (:ticket:`26557`). diff --git a/tests/model_fields/test_genericipaddressfield.py b/tests/model_fields/test_genericipaddressfield.py index 7a3705ef18..c65fe805cb 100644 --- a/tests/model_fields/test_genericipaddressfield.py +++ b/tests/model_fields/test_genericipaddressfield.py @@ -29,6 +29,14 @@ class GenericIPAddressFieldTests(TestCase): o = GenericIPAddress.objects.get() self.assertIsNone(o.ip) + def test_blank_string_saved_as_null(self): + o = GenericIPAddress.objects.create(ip='') + o.refresh_from_db() + self.assertIsNone(o.ip) + GenericIPAddress.objects.update(ip='') + o.refresh_from_db() + self.assertIsNone(o.ip) + def test_save_load(self): instance = GenericIPAddress.objects.create(ip='::1') loaded = GenericIPAddress.objects.get() |
