Permalink
Browse files

Removed IPAddressField per deprecation timeline; refs #20439.

  • Loading branch information...
1 parent 5008a4d commit 33457cd3b0da69320d3f66bb6d5a673950c5032f @timgraham timgraham committed Jan 18, 2015
@@ -1894,13 +1894,13 @@ def formfield(self, **kwargs):
class IPAddressField(Field):
empty_strings_allowed = False
description = _("IPv4 address")
- system_check_deprecated_details = {
+ system_check_removed_details = {
'msg': (
- 'IPAddressField has been deprecated. Support for it (except in '
- 'historical migrations) will be removed in Django 1.9.'
+ 'IPAddressField has been removed except for support in '
+ 'historical migrations.'
),
'hint': 'Use GenericIPAddressField instead.',
- 'id': 'fields.W900',
+ 'id': 'fields.E900',
}
def __init__(self, *args, **kwargs):
@@ -1921,11 +1921,6 @@ def get_prep_value(self, value):
def get_internal_type(self):
return "IPAddressField"
- def formfield(self, **kwargs):
- defaults = {'form_class': forms.IPAddressField}
- defaults.update(kwargs)
- return super(IPAddressField, self).formfield(**defaults)
-
class GenericIPAddressField(Field):
empty_strings_allowed = False
View
@@ -27,7 +27,7 @@
from django.utils.encoding import smart_text, force_str, force_text
from django.utils.ipv6 import clean_ipv6_address
from django.utils.dateparse import parse_duration
-from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning, RenameMethodsBase
+from django.utils.deprecation import RemovedInDjango20Warning, RenameMethodsBase
from django.utils.duration import duration_string
from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
@@ -43,7 +43,7 @@
'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField',
'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField',
'ComboField', 'MultiValueField', 'FloatField', 'DecimalField',
- 'SplitDateTimeField', 'IPAddressField', 'GenericIPAddressField', 'FilePathField',
+ 'SplitDateTimeField', 'GenericIPAddressField', 'FilePathField',
'SlugField', 'TypedChoiceField', 'TypedMultipleChoiceField', 'UUIDField',
)
@@ -1206,20 +1206,6 @@ def compress(self, data_list):
return None
-class IPAddressField(CharField):
- default_validators = [validators.validate_ipv4_address]
-
- def __init__(self, *args, **kwargs):
- warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
- RemovedInDjango19Warning)
- super(IPAddressField, self).__init__(*args, **kwargs)
-
- def to_python(self, value):
- if value in self.empty_values:
- return ''
- return value.strip()
-
-
class GenericIPAddressField(CharField):
def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
self.unpack_ipv4 = unpack_ipv4
View
@@ -95,8 +95,11 @@ Fields
* **fields.E160**: The options ``auto_now``, ``auto_now_add``, and ``default``
are mutually exclusive. Only one of these options may be present.
* **fields.W161**: Fixed default value provided.
+* **fields.E900**: ``IPAddressField`` has been removed except for support in
+ historical migrations.
* **fields.W900**: ``IPAddressField`` has been deprecated. Support for it
- (except in historical migrations) will be removed in Django 1.9.
+ (except in historical migrations) will be removed in Django 1.9. *This check
+ appeared in Django 1.7 and 1.8*.
File Fields
~~~~~~~~~~~
View
@@ -719,22 +719,6 @@ For each field, we describe the default widget used if you don't specify
These control the range of values permitted in the field.
-``IPAddressField``
-~~~~~~~~~~~~~~~~~~
-
-.. class:: IPAddressField(**kwargs)
-
- .. deprecated:: 1.7
- This field has been deprecated in favor of
- :class:`~django.forms.GenericIPAddressField`.
-
- * Default widget: :class:`TextInput`
- * Empty value: ``''`` (an empty string)
- * Normalizes to: A Unicode object.
- * Validates that the given value is a valid IPv4 address, using a regular
- expression.
- * Error message keys: ``required``, ``invalid``
-
``GenericIPAddressField``
~~~~~~~~~~~~~~~~~~~~~~~~~
View
@@ -892,18 +892,6 @@ An integer. Values from ``-2147483648`` to ``2147483647`` are safe in all
databases supported by Django. The default form widget for this field is a
:class:`~django.forms.TextInput`.
-``IPAddressField``
-------------------
-
-.. class:: IPAddressField([**options])
-
-.. deprecated:: 1.7
- This field has been deprecated in favor of
- :class:`~django.db.models.GenericIPAddressField`.
-
-An IP address, in string format (e.g. "192.0.2.30"). The default form widget
-for this field is a :class:`~django.forms.TextInput`.
-
``GenericIPAddressField``
-------------------------
View
@@ -96,7 +96,7 @@ field classes did not correctly convert their arguments:
* :class:`~django.db.models.FilePathField`
* :class:`~django.db.models.GenericIPAddressField`
-* :class:`~django.db.models.IPAddressField`
+* ``IPAddressField``
These three fields have been updated to convert their arguments to the
correct types before querying.
View
@@ -95,7 +95,7 @@ field classes did not correctly convert their arguments:
* :class:`~django.db.models.FilePathField`
* :class:`~django.db.models.GenericIPAddressField`
-* :class:`~django.db.models.IPAddressField`
+* ``IPAddressField``
These three fields have been updated to convert their arguments to the
correct types before querying.
View
@@ -95,7 +95,7 @@ field classes did not correctly convert their arguments:
* :class:`~django.db.models.FilePathField`
* :class:`~django.db.models.GenericIPAddressField`
-* :class:`~django.db.models.IPAddressField`
+* ``IPAddressField``
These three fields have been updated to convert their arguments to the
correct types before querying.
View
@@ -876,10 +876,8 @@ Miscellaneous
:class:`~django.forms.ModelMultipleChoiceField`.
* Some :attr:`~django.forms.Field.error_messages` for
- :class:`~django.forms.IntegerField`,
- :class:`~django.forms.EmailField`,
- :class:`~django.forms.IPAddressField`,
- :class:`~django.forms.GenericIPAddressField`, and
+ :class:`~django.forms.IntegerField`, :class:`~django.forms.EmailField`,
+ ``IPAddressField``, :class:`~django.forms.GenericIPAddressField`, and
:class:`~django.forms.SlugField` have been suppressed because they
duplicated error messages already provided by validators tied to the fields.
View
@@ -1591,8 +1591,8 @@ better handle the case of selectively showing inlines on a ``ModelAdmin``.
``IPAddressField``
~~~~~~~~~~~~~~~~~~
-The :class:`django.db.models.IPAddressField` and
-:class:`django.forms.IPAddressField` fields have been deprecated in favor of
+The ``django.db.models.IPAddressField`` and ``django.forms.IPAddressField``
+fields have been deprecated in favor of
:class:`django.db.models.GenericIPAddressField` and
:class:`django.forms.GenericIPAddressField`.
@@ -29,7 +29,6 @@ class CaseTestModel(models.Model):
float = models.FloatField(null=True, db_column='float_field')
if Image:
image = models.ImageField(null=True)
- ip_address = models.IPAddressField(null=True)
generic_ip_address = models.GenericIPAddressField(null=True)
null_boolean = models.NullBooleanField()
positive_integer = models.PositiveIntegerField(null=True)
@@ -752,21 +752,6 @@ def test_update_image(self):
transform=lambda o: (o.integer, six.text_type(o.image))
)
- def test_update_ip_address(self):
- CaseTestModel.objects.update(
- ip_address=Case(
- # fails on postgresql if output_field is not set explicitly
- When(integer=1, then=Value('1.1.1.1')),
- When(integer=2, then=Value('2.2.2.2')),
- output_field=models.IPAddressField(),
- ),
- )
- self.assertQuerysetEqual(
- CaseTestModel.objects.all().order_by('pk'),
- [(1, '1.1.1.1'), (2, '2.2.2.2'), (3, None), (2, '2.2.2.2'), (3, None), (3, None), (4, None)],
- transform=attrgetter('integer', 'ip_address')
- )
-
def test_update_generic_ip_address(self):
CaseTestModel.objects.update(
generic_ip_address=Case(
@@ -5,12 +5,11 @@
from django.forms import (
BooleanField, CharField, ChoiceField, DateField, DateTimeField,
DecimalField, EmailField, FileField, FloatField, Form,
- GenericIPAddressField, IntegerField, IPAddressField, ModelChoiceField,
+ GenericIPAddressField, IntegerField, ModelChoiceField,
ModelMultipleChoiceField, MultipleChoiceField, RegexField,
SplitDateTimeField, TimeField, URLField, utils, ValidationError,
)
-from django.test import ignore_warnings, TestCase
-from django.utils.deprecation import RemovedInDjango19Warning
+from django.test import TestCase
from django.utils.safestring import mark_safe
from django.utils.encoding import python_2_unicode_compatible
@@ -197,16 +196,6 @@ def test_splitdatetimefield(self):
self.assertFormErrors(['REQUIRED'], f.clean, '')
self.assertFormErrors(['INVALID DATE', 'INVALID TIME'], f.clean, ['a', 'b'])
- @ignore_warnings(category=RemovedInDjango19Warning)
- def test_ipaddressfield(self):
- e = {
- 'required': 'REQUIRED',
- 'invalid': 'INVALID IP ADDRESS',
- }
- f = IPAddressField(error_messages=e)
- self.assertFormErrors(['REQUIRED'], f.clean, '')
- self.assertFormErrors(['INVALID IP ADDRESS'], f.clean, '127.0.0')
-
def test_generic_ipaddressfield(self):
e = {
'required': 'REQUIRED',
@@ -5,17 +5,16 @@
from django.forms import (
CharField, DateField, EmailField, FileField, Form, GenericIPAddressField,
- HiddenInput, ImageField, IPAddressField, MultipleChoiceField,
- MultiValueField, MultiWidget, PasswordInput, SelectMultiple, SlugField,
- SplitDateTimeField, SplitDateTimeWidget, TextInput, URLField,
+ HiddenInput, ImageField, MultipleChoiceField, MultiValueField, MultiWidget,
+ PasswordInput, SelectMultiple, SlugField, SplitDateTimeField,
+ SplitDateTimeWidget, TextInput, URLField,
)
from django.forms.extras import SelectDateWidget
from django.forms.utils import ErrorList
-from django.test import TestCase, ignore_warnings, override_settings
+from django.test import TestCase, override_settings
from django.utils import six
from django.utils import translation
from django.utils.dates import MONTHS_AP
-from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text, smart_text, python_2_unicode_compatible
from .test_error_messages import AssertFormErrorsMixin
@@ -483,26 +482,6 @@ class ComplexFieldForm(Form):
self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00')
- @ignore_warnings(category=RemovedInDjango19Warning)
- def test_ipaddress(self):
- f = IPAddressField()
- self.assertFormErrors(['This field is required.'], f.clean, '')
- self.assertFormErrors(['This field is required.'], f.clean, None)
- self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, 'foo')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '127.0.0.')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
-
- f = IPAddressField(required=False)
- self.assertEqual(f.clean(''), '')
- self.assertEqual(f.clean(None), '')
- self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, 'foo')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '127.0.0.')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
- self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
-
def test_generic_ipaddress_invalid_arguments(self):
self.assertRaises(ValueError, GenericIPAddressField, protocol="hamster")
self.assertRaises(ValueError, GenericIPAddressField, protocol="ipv4", unpack_ipv4=True)
@@ -59,7 +59,6 @@ class ColumnTypes(models.Model):
file_path_field = models.FilePathField()
float_field = models.FloatField()
int_field = models.IntegerField()
- ip_address_field = models.IPAddressField()
gen_ip_adress_field = models.GenericIPAddressField(protocol="ipv4")
pos_int_field = models.PositiveIntegerField()
pos_small_int_field = models.PositiveSmallIntegerField()
View
@@ -61,11 +61,9 @@ def test_field_types(self):
assertFieldType('file_field', "models.CharField(max_length=100)")
assertFieldType('file_path_field', "models.CharField(max_length=100)")
if connection.features.can_introspect_ip_address_field:
- assertFieldType('ip_address_field', "models.GenericIPAddressField()")
assertFieldType('gen_ip_adress_field', "models.GenericIPAddressField()")
elif (connection.features.can_introspect_max_length and
not connection.features.interprets_empty_strings_as_nulls):
- assertFieldType('ip_address_field', "models.CharField(max_length=15)")
assertFieldType('gen_ip_adress_field', "models.CharField(max_length=39)")
if (connection.features.can_introspect_max_length and
not connection.features.interprets_empty_strings_as_nulls):
@@ -0,0 +1,22 @@
+from django.core import checks
+from django.db import models
+
+from .base import IsolatedModelsTestCase
+
+
+class DeprecatedFieldssTests(IsolatedModelsTestCase):
+ def test_IPAddressField_deprecated(self):
+ class IPAddressModel(models.Model):
+ ip = models.IPAddressField()
+
+ model = IPAddressModel()
+ self.assertEqual(
+ model.check(),
+ [checks.Error(
+ 'IPAddressField has been removed except for support in '
+ 'historical migrations.',
+ hint='Use GenericIPAddressField instead.',
+ obj=IPAddressModel._meta.get_field('ip'),
+ id='fields.E900',
+ )],
+ )
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='IPAddressField',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+ ('ip', models.IPAddressField(null=True, blank=True)),
+ ],
+ ),
+ ]
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('migrations', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='ipaddressfield',
+ name='ip',
+ ),
+ ]
@@ -0,0 +1,22 @@
+from django.core.management import call_command
+from django.test import override_settings
+
+from .test_base import MigrationTestBase
+
+
+class Tests(MigrationTestBase):
+ """
+ Deprecated model fields should still be usable in historic migrations.
+ """
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.deprecated_field_migrations"})
+ def test_migrate(self):
+ # Make sure no tables are created
+ self.assertTableNotExists("migrations_ipaddressfield")
+ # Run migration
+ call_command("migrate", verbosity=0)
+ # Make sure the right tables exist
+ self.assertTableExists("migrations_ipaddressfield")
+ # Unmigrate everything
+ call_command("migrate", "migrations", "zero", verbosity=0)
+ # Make sure it's all gone
+ self.assertTableNotExists("migrations_ipaddressfield")
Oops, something went wrong.

0 comments on commit 33457cd

Please sign in to comment.