mirror of
https://github.com/django/django.git
synced 2025-07-20 09:39:13 +00:00
[1.9.x] Fixed #26557 -- Converted empty strings to None when saving GenericIPAddressField.
Backport of 4681d65048ca2553895e10c2c492997b0a78ffba from master
This commit is contained in:
parent
d2338bae78
commit
e0af590bde
@ -497,7 +497,7 @@ class BaseDatabaseOperations(object):
|
|||||||
Transforms a string representation of an IP address into the expected
|
Transforms a string representation of an IP address into the expected
|
||||||
type for the backend driver.
|
type for the backend driver.
|
||||||
"""
|
"""
|
||||||
return value
|
return value or None
|
||||||
|
|
||||||
def year_lookup_bounds_for_date_field(self, value):
|
def year_lookup_bounds_for_date_field(self, value):
|
||||||
"""
|
"""
|
||||||
|
@ -24,3 +24,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a regression causing the cached template loader to crash when using
|
* Fixed a regression causing the cached template loader to crash when using
|
||||||
template names starting with a dash (:ticket:`26536`).
|
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`).
|
||||||
|
@ -900,6 +900,14 @@ class GenericIPAddressFieldTests(test.TestCase):
|
|||||||
o = GenericIPAddress.objects.get()
|
o = GenericIPAddress.objects.get()
|
||||||
self.assertIsNone(o.ip)
|
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):
|
def test_save_load(self):
|
||||||
instance = GenericIPAddress.objects.create(ip='::1')
|
instance = GenericIPAddress.objects.create(ip='::1')
|
||||||
loaded = GenericIPAddress.objects.get()
|
loaded = GenericIPAddress.objects.get()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user