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:51:48 +0200
commitceb1ffcc8da92a82338582bc6801de4bc8f05e32 (patch)
tree5aa7cf45b99ec598ab0f50d41d81caae01971acc /django
parentc548c8d0d1112d2c4bace2eebf73ede35300d842 (diff)
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).
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 1143bb9530..b9f320c0e0 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1402,9 +1402,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)