summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAndy Chosak <chosak@gmail.com>2014-10-08 15:12:42 -0400
committerAnssi Kääriäinen <akaariai@gmail.com>2014-11-03 15:59:17 +0200
commit12e5b87b89074cd0380ddcdadd24a6c621178c07 (patch)
tree92dd86e2072c9f66feab29dda5d82e80a3d2041b /django
parent74d0311d6b1fb3ab16072d5fad9de8b996e8af1c (diff)
[1.7.x] Fixed #23420 - broken warning for unbound naive datetime objects
Fixed issue with warning message displayed for unbound naive datetime objects when USE_TZ is True. Adds unit test that demonstrates the issue (discoverable when using a custom lookup in MySQL). Backport of ceb1ffcc8d from master. Conflicts: tests/custom_lookups/tests.py
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/__init__.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 0db51ca60d..a734b21676 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1272,9 +1272,13 @@ class DateTimeField(DateField):
# For backwards compatibility, interpret naive datetimes in local
# time. This won't work during DST change, but we can't do much
# about it, so we let the exceptions percolate up the call stack.
- warnings.warn("DateTimeField %s.%s received a naive datetime (%s)"
+ try:
+ name = '%s.%s' % (self.model.__name__, self.name)
+ except AttributeError:
+ name = '(unbound)'
+ warnings.warn("DateTimeField %s received a naive datetime (%s)"
" while time zone support is active." %
- (self.model.__name__, self.name, value),
+ (name, value),
RuntimeWarning)
default_timezone = timezone.get_default_timezone()
value = timezone.make_aware(value, default_timezone)