mirror of https://github.com/django/django.git
Fixed #24078 -- Removed empty strings from GenericIPAddressField
This commit is contained in:
parent
9b057b51ce
commit
5a4ac4ead9
|
@ -1910,7 +1910,7 @@ class IPAddressField(Field):
|
|||
|
||||
|
||||
class GenericIPAddressField(Field):
|
||||
empty_strings_allowed = True
|
||||
empty_strings_allowed = False
|
||||
description = _("IP address")
|
||||
default_error_messages = {}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue