dumpdata --format=yaml, dates, and USE_TZ

111 views
Skip to first unread message

James Schneider

unread,
Dec 5, 2013, 2:57:59 AM12/5/13
to django...@googlegroups.com
Hello all,

I'm hitting strange runtime errors when using some fixtures, and I wanted to validate with others before I file a bug for 1.6...

Here are two examples of dumpdata commands using the same database and same data:

$ python manage.py dumpdata auth.user --format=json --indent=4
<snip snip>
{
    "pk": 2,
    "model": "auth.user",
    "fields": {
        "username": "derp",
        "first_name": "",
        "last_name": "",
        "is_active": true,
        "is_superuser": true,
        "is_staff": true,
        "last_login": "2013-12-05T07:35:34Z",
        "groups": [],
        "user_permissions": [],
        "password": "pbkdf2_sha256$12000$U9pLOBwfwkwA$39lGySA0gyq5MIK3akySO1XWju9bI6nR+kN0oJju0LY=",
        "email": "",
        "date_joined": "2013-12-05T07:35:34Z"
    }
}



$ python manage.py dumpdata auth.user --format=yaml --indent=4
<snip snip>
-   fields:
        date_joined: 2013-12-05 07:35:34+00:00
        email: ''
        first_name: ''
        groups: []
        is_active: true
        is_staff: true
        is_superuser: true
        last_login: 2013-12-05 07:35:34+00:00
        last_name: ''
        password: pbkdf2_sha256$12000$U9pLOBwfwkwA$39lGySA0gyq5MIK3akySO1XWju9bI6nR+kN0oJju0LY=
        user_permissions: []
        username: derp
    model: auth.user
    pk: 2



Notice the DateTime formatting differences generated between the two formats in the date_joined and last_login fields.



When I use both of these outputs as part of a fixture file, the JSON file works fine, but loading the YAML file produces a runtime warning as if the TZ data is not specified in the date string for the two fields I mentioned above, as shown here:

$ python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table project_auth_projectperm
Creating table project_auth_projectrole_perms
Creating table project_auth_projectrole
Creating table project_competitions_competition

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no
Installing custom SQL ...
Installing indexes ...
/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-05 07:35:34) 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-05 07:35:34) while time zone support is active.
  RuntimeWarning)

Installed 1 object(s) from 1 fixture(s)



Loading the same fixture above via JSON works fine without warnings.


Frankly, any code I've written should be irrelevant, since the erroneous fields are from contrib.auth and created via the provided manage.py commands.


Am I crazy here? Or is the YAML serialization broken? If I get validation here then I'll file a bug.

TIA,

James


Aymeric Augustin

unread,
Dec 29, 2013, 4:42:16 PM12/29/13
to django...@googlegroups.com
It's a bug in PyYAML: https://code.djangoproject.com/ticket/18867

--
Aymeric.

Reply all
Reply to author
Forward
0 new messages