Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16246 -- Fixed GenericIPAddressField tests on PostgreSQL.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 823bac36db2e4679d03fdc36e318da779767cac6 1 parent 479f2bc
Jannis Leidel authored June 13, 2011
7  django/db/models/fields/__init__.py
@@ -910,6 +910,7 @@ class BigIntegerField(IntegerField):
910 910
     empty_strings_allowed = False
911 911
     description = _("Big (8 byte) integer")
912 912
     MAX_BIGINT = 9223372036854775807
  913
+
913 914
     def get_internal_type(self):
914 915
         return "BigIntegerField"
915 916
 
@@ -922,6 +923,7 @@ def formfield(self, **kwargs):
922 923
 class IPAddressField(Field):
923 924
     empty_strings_allowed = False
924 925
     description = _("IPv4 address")
  926
+
925 927
     def __init__(self, *args, **kwargs):
926 928
         kwargs['max_length'] = 15
927 929
         Field.__init__(self, *args, **kwargs)
@@ -956,6 +958,11 @@ def to_python(self, value):
956 958
                 self.unpack_ipv4, self.error_messages['invalid'])
957 959
         return value
958 960
 
  961
+    def get_db_prep_value(self, value, connection, prepared=False):
  962
+        if not prepared:
  963
+            value = self.get_prep_value(value)
  964
+        return value or None
  965
+
959 966
     def get_prep_value(self, value):
960 967
         if value and ':' in value:
961 968
             try:
4  django/forms/fields.py
@@ -965,8 +965,8 @@ def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
965 965
         super(GenericIPAddressField, self).__init__(*args, **kwargs)
966 966
 
967 967
     def to_python(self, value):
968  
-        if not value:
969  
-            return ''
  968
+        if value in validators.EMPTY_VALUES:
  969
+            return u''
970 970
         if value and ':' in value:
971 971
                 return clean_ipv6_address(value,
972 972
                     self.unpack_ipv4, self.error_messages['invalid'])
6  tests/modeltests/validation/models.py
@@ -84,9 +84,9 @@ class UniqueErrorsModel(models.Model):
84 84
     number = models.IntegerField(unique=True, error_messages={'unique': u'Custom unique number message.'})
85 85
 
86 86
 class GenericIPAddressTestModel(models.Model):
87  
-    generic_ip = models.GenericIPAddressField(blank=True, unique=True)
88  
-    v4_ip = models.GenericIPAddressField(blank=True, protocol="ipv4")
89  
-    v6_ip = models.GenericIPAddressField(blank=True, protocol="ipv6")
  87
+    generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
  88
+    v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4")
  89
+    v6_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv6")
90 90
 
91 91
 class GenericIPAddrUnpackUniqueTest(models.Model):
92 92
     generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True)

0 notes on commit 823bac3

Please sign in to comment.
Something went wrong with that request. Please try again.