Opened 2 years ago

Closed 2 years ago

#21578 closed Bug (duplicate) dumpdata --format=yaml produces naive datetimes in fixtures

Reported by: disturbedmime Owned by: nobody
Component: Core (Serialization) Version: 1.6
Severity: Normal Keywords:
Cc: jrschneider83@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The following runtime warnings are produced when --format=yaml is used with dumpdata:

/usr/local/lib/python2.7/dist-packages/django/db/models/fields/ RuntimeWarning: DateTimeField User.last_login received a naive datetime (2013-12-08 07:47:16.243704) while time zone support is active.


/usr/local/lib/python2.7/dist-packages/django/db/models/fields/ RuntimeWarning: DateTimeField User.date_joined received a naive datetime (2013-12-08 07:47:16.243704) while time zone support is active.


These warnings are easily reproducible with no custom application code. The following steps can be used to replicate the warnings:

Using 1.6/Python 2.7:

  1. startproject dummy_project
  2. cd dummy_project
  3. python startapp dummy_app
  4. Edit dummy_project/ and add 'dummy_app' to INSTALLED_APPS
  5. python syncdb
  6. Create new superuser as part of syncdb process.
  7. mkdir dummy_app/fixtures
  8. python dumpdata --format=yaml --indent=4 > dummy_app/fixtures/initial_data.yaml
  9. python flush
  10. Do NOT create a new user, as the above YAML dump should contain a superuser.
  11. The above runtime warnings are generated.

Repeating the above steps using JSON produces no warnings. Note that the datetime format generated during the JSON dump is different.

An initial glance using the above test would indicate that the warnings are only cosmetic, and that the data is inserted into the database correctly, however, given the issue either generating the correct format, or interpreting the given format, this may lead to other problems and probably shouldn't be left to chance.

Examples of format dumps to show differences:

JSON: "last_login": "2013-12-08T08:10:52.397Z"

YAML: last_login: 2013-12-08 08:10:52.397046+00:00

Both of these were dumps using the above steps, based on the same data, and making no other changes to the DB.

Change History (3)

comment:1 Changed 2 years ago by disturbedmime

  • Cc jrschneider83@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 years ago by bmispelon


This is a duplicate of #18867 which was marked as invalid because this is a bug in the PyYAML library and not in Django.

That ticket is fairly old so if there's been new developments, feel free to reopen that other ticket so that we can keep the discussion in one place.


comment:3 Changed 2 years ago by bmispelon

  • Resolution set to duplicate
  • Status changed from new to closed

(forgot to close the ticket)

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