Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed the PostGIS circular imports caused by 1506c71.

Thanks to @loic for the help and @timgraham for the review.

refs #12030.
  • Loading branch information...
commit b9e50e47742f67dcf3c37aad989b350e8255154e 1 parent 5233b36
@charettes charettes authored
Showing with 15 additions and 8 deletions.
  1. +15 −8 django/db/models/fields/__init__.py
View
23 django/db/models/fields/__init__.py
@@ -20,7 +20,7 @@
from django.utils.datastructures import DictWrapper
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.deprecation import RemovedInDjango19Warning
-from django.utils.functional import curry, total_ordering, Promise
+from django.utils.functional import cached_property, curry, total_ordering, Promise
from django.utils.text import capfirst
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@@ -157,7 +157,6 @@ def __init__(self, verbose_name=None, name=None, primary_key=False,
Field.creation_counter += 1
self._validators = validators # Store for deconstruction later
- self.validators = self.default_validators + validators
messages = {}
for c in reversed(self.__class__.__mro__):
@@ -447,6 +446,12 @@ def to_python(self, value):
"""
return value
+ @cached_property
+ def validators(self):
+ # Some validators can't be created at field initialization time.
+ # This method provides a way to delay their creation until required.
+ return self.default_validators + self._validators
+
def run_validators(self, value):
if value in self.empty_values:
return
@@ -1561,16 +1566,18 @@ class IntegerField(Field):
}
description = _("Integer")
- def __init__(self, *args, **kwargs):
- default_validators = self.default_validators[:]
+ @cached_property
+ def validators(self):
+ # These validators can't be added at field initialization time since
+ # they're based on values retrieved from `connection`.
+ range_validators = []
internal_type = self.get_internal_type()
min_value, max_value = connection.ops.integer_field_range(internal_type)
if min_value is not None:
- default_validators.append(validators.MinValueValidator(min_value))
+ range_validators.append(validators.MinValueValidator(min_value))
if max_value is not None:
- default_validators.append(validators.MaxValueValidator(max_value))
- self.default_validators = default_validators
- super(IntegerField, self).__init__(*args, **kwargs)
+ range_validators.append(validators.MaxValueValidator(max_value))
+ return super(IntegerField, self).validators + range_validators
def get_prep_value(self, value):
value = super(IntegerField, self).get_prep_value(value)

0 comments on commit b9e50e4

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