Skip to content

Commit

Permalink
Fixed #24078 -- Removed empty strings from GenericIPAddressField
Browse files Browse the repository at this point in the history
  • Loading branch information
jarshwah authored and timgraham committed Jan 7, 2015
1 parent 9b057b5 commit 5a4ac4e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ def formfield(self, **kwargs):


class GenericIPAddressField(Field):
empty_strings_allowed = True
empty_strings_allowed = False
description = _("IP address")
default_error_messages = {}

Expand Down
5 changes: 5 additions & 0 deletions docs/releases/1.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/model_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions tests/model_fields/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
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):
Expand Down Expand Up @@ -688,6 +688,14 @@ def test_genericipaddressfield_formfield_protocol(self):
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):
Expand Down

0 comments on commit 5a4ac4e

Please sign in to comment.