#18867: Restoring YAML fixtures with DateTimeField causes timezone warnings
-------------------------------------+-------------------------------------
     Reporter:  aigarius@…           |                    Owner:  aaugustin
         Type:                       |                   Status:  closed
  Cleanup/optimization               |                  Version:  1.4
    Component:  Database layer       |               Resolution:  invalid
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  0
     Keywords:                       |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by dcreager):

 I've found a workaround that I can't find documented anywhere else, so I'm
 posting it here for the record.

 The key is to force PyYAML to interpret the timestamp values as strings,
 and not let it perform the conversion to a `datetime`.  PyYAML will then
 pass the bare string value on to Django, which will correctly parse a
 timezone-aware `datetime`.

 For this to work you must make sure that all of the following are true:

 1. Don't use the `!!timestamp` YAML tag
 2. Enclose the timestamp values in quotes (which bypasses PyYAML's logic
 for automatically detecting a value's type based on what it looks like)
 3. Include timezone information in the timestamp value

 When we do all three of these steps with our fixture data, we don't see
 any naive datetime warnings.  Note that this doesn't help any with #21578,
 since the data dumper produces YAML content that doesn't follow all three
 of these rules.  We've had to resort to a manual post-processing step to
 massage the timestamp values.  Not ideal, but it works.

--
Ticket URL: <https://code.djangoproject.com/ticket/18867#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/076.8f5273aa7025374eaba70ad7ceef3ca1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to