Fixed #24078 -- Removed empty strings from GenericIPAddressField

This commit is contained in:
Josh Smeaton 2015-01-05 21:32:25 +11:00 committed by Tim Graham
parent 9b057b51ce
commit 5a4ac4ead9
4 changed files with 23 additions and 6 deletions

View File

@ -1910,7 +1910,7 @@ class IPAddressField(Field):
class GenericIPAddressField(Field):
empty_strings_allowed = True
empty_strings_allowed = False
description = _("IP address")
default_error_messages = {}

View File

@ -1009,6 +1009,11 @@ Miscellaneous
different in some cases. There is no change to default values which are the
result of a callable.
* ``GenericIPAddressField.empty_strings_allowed`` is now ``False``. Database
backends that interpet empty strings as null (only Oracle among the backends
that Django includes) will no longer convert null values back to an empty
string. This is consistent with other backends.
.. _deprecated-features-1.8:
Features deprecated in 1.8

View File

@ -176,6 +176,10 @@ class VerboseNameField(models.Model):
field22 = models.URLField("verbose field22")
class GenericIPAddress(models.Model):
ip = models.GenericIPAddressField(null=True, protocol='ipv4')
###############################################################################
# These models aren't used in any test, just here to ensure they validate
# successfully.

View File

@ -22,11 +22,11 @@ from django.utils import six
from django.utils.functional import lazy
from .models import (
Foo, Bar, Whiz, BigD, BigS, BigIntegerModel, Post, NullBooleanModel,
BooleanModel, PrimaryKeyCharModel, DataModel, Document, RenamedField,
DateTimeModel, VerboseNameField, FksToBooleans, FkToChar, FloatModel,
SmallIntegerModel, IntegerModel, PositiveSmallIntegerModel, PositiveIntegerModel,
WhizIter, WhizIterEmpty)
Bar, BigD, BigIntegerModel, BigS, BooleanModel, DataModel, DateTimeModel,
Document, FksToBooleans, FkToChar, FloatModel, Foo, GenericIPAddress,
IntegerModel, NullBooleanModel, PositiveIntegerModel, PositiveSmallIntegerModel,
Post, PrimaryKeyCharModel, RenamedField, SmallIntegerModel, VerboseNameField,
Whiz, WhizIter, WhizIterEmpty)
class BasicFieldTests(test.TestCase):
@ -688,6 +688,14 @@ class GenericIPAddressFieldTests(test.TestCase):
form_field = model_field.formfield()
self.assertRaises(ValidationError, form_field.clean, '127.0.0.1')
def test_null_value(self):
"""
Null values should be resolved to None in Python (#24078).
"""
GenericIPAddress.objects.create()
o = GenericIPAddress.objects.get()
self.assertIsNone(o.ip)
class PromiseTest(test.TestCase):
def test_AutoField(self):