Opened 12 years ago

Last modified 6 years ago

#18867 closed Cleanup/optimization

Restoring YAML fixtures with DateTimeField causes timezone warnings — at Version 2

Reported by: aigarius@… Owned by: Aymeric Augustin
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords:
Cc: michi.schwarz@…, tehfink Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

Loading a YAML fixture with a timezone aware DateTimeField in Django 1.4 will cause the following warning even if the field is defined with timezone information in the YAML file

django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-08-27 13:01:56.784734) while time zone support is active.

Excerpt from testdata.yaml

[...] , insert_date: !!timestamp '2012-08-27 13:01:56.784734+00:00', [...]

The test data is loaded by adding "fixtures = testdata" at the start of a test case class.

This bug is mentioned in Django test suite - django/trunk/tests/modeltests/timezones/tests.py:SerializationTests

Note: the trick of "MyTests = override_settings(USE_TZ=False)(MyTests)" (from #17940) often does not work as expected, because you can then get "ValueError: SQLite backend does not support timezone-aware datetimes when USE_TZ is False" during fixture loading

Change History (2)

comment:1 by Aymeric Augustin, 12 years ago

Component: Database layer (models, ORM)Documentation
Owner: changed from nobody to Aymeric Augustin
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Indeed, this is a bug in PyYAML, as described in this comment.

There hasn't been any activity whatsoever on PyYAML's tracker, besides the creation of new tickets, since over one year. The project looks abandoned.

We aren't going to removing support for YAML fixtures now just because of this bug in PyYAML. We can document this as a known problem here and tell people to use JSON fixtures.

Other ideas?

comment:2 by Russell Keith-Magee, 12 years ago

Description: modified (diff)

Historically, we haven't modified Django's docs to point out problems in downstream libraries -- the reasoning being that if the bug is fixed, there's never an action to correct Django's documentation and remove the warning. We've usually relied on the ticket tracker making it easy to find such problems.

Note: See TracTickets for help on using tickets.
Back to Top