Opened 10 years ago

Closed 10 years ago

#21578 closed Bug (duplicate)

manage.py dumpdata --format=yaml produces naive datetimes in fixtures

Reported by: James Schneider 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

Description

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

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

RuntimeWarning)

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

RuntimeWarning)

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. django-admin.py startproject dummy_project
  2. cd dummy_project
  3. python manage.py startapp dummy_app
  4. Edit dummy_project/settings.py and add 'dummy_app' to INSTALLED_APPS
  5. python manage.py syncdb
  6. Create new superuser as part of syncdb process.
  7. mkdir dummy_app/fixtures
  8. python manage.py dumpdata --format=yaml --indent=4 > dummy_app/fixtures/initial_data.yaml
  9. python manage.py 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 by James Schneider, 10 years ago

Cc: jrschneider83@… added

comment:2 by Baptiste Mispelon, 10 years ago

Hi,

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.

Thanks.

comment:3 by Baptiste Mispelon, 10 years ago

Resolution: duplicate
Status: newclosed

(forgot to close the ticket)

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