Please improve warning message "received a naive datetime while time zone support is active"
|Reported by:||gcc||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The warning message usually shows:
BadDataError: ('payment.Order', RuntimeWarning(u'DateTimeField received a naive datetime (2013-01-03 19:45:41.532391) while time zone support is active.',))
However it doesn't actually show which field this happened to, which makes it hard to debug without inserting breakpoints.
This three-line change to django.db.models.fields.DateTimeField:
def get_prep_value(self, value): value = self.to_python(value) if value is not None and settings.USE_TZ and timezone.is_naive(value): ... - warnings.warn("DateTimeField received a naive datetime (%s)" - " while time zone support is active." % value, + warnings.warn("DateTimeField %s.%s received a naive datetime (%s)" + " while time zone support is active." % + (self.model.__name__, self.name, value), RuntimeWarning)
Which results in this output instead:
DateTimeField Order.created received a naive datetime (2013-01-03 20:11:24.084774) while time zone support is active.
Change History (8)
comment:1 Changed 3 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
Changed 3 years ago by vajrasky
comment:6 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>
- Resolution set to fixed
- Status changed from new to closed