Request

Change executed raw mysql queries to return timezone aware datetimes.

Explanation

Django 1.9 changed so that raw queries executed in mysql do not return 
timezone aware datetimes. Removing this feature now requires that all 
custom SQL queries involving datetimes have special handling to convert the 
datetimes to timezone aware datetimes. 

The explanation for this was that the conversion was happening globally and 
having adverse affects on 3rd parties. There was also a desire to allow 
per-db timezone settings. 

While sqlite converters are registered globally, mysql converters appear to 
be registered per connection. I'm not sure why mysql was included in this 
change.  It should be possible instead to use the per db TIMEZONE setting 
at the connection level for mysql.  

I read through the code and all related to discussion and must confess I'm 
still not sure I understand the reasoning for this change happening in 
mysql.  I'm posting here hoping to understand better why the mysql 
connection datetime behavior doesn’t key off the per db TIMEZONE setting 
and global USE_TZ settings.

In our local codebase we plan to monkeypatch django to continue returning 
timezone aware datetimes for mysql, thus saving us from manually fixing 
many many queries.  Is this a bad plan? Is there a better way?

Thank you,

Bryce Drennan

Senior Engineer @ Circleup

References

   1. 
   
   https://code.djangoproject.com/ticket/19738 - "manage.py shell" on a 
   fresh project raises RuntimeWarning about naive datetime, if IPython is 
   installed
   2. 
   
   https://code.djangoproject.com/ticket/23820 - Make it possible to 
   override USE_TZ & TIME_ZONE on a per-database basis
   3. 
   
   https://github.com/django/django/pull/4601 - Refactor adaptation and 
   conversion of aware datetimes
   4. 
   
   
   
https://groups.google.com/forum/#!searchin/django-developers/datetimes%7Csort:date/django-developers/Ci_cs0KTagM/iAduocfXFOcJ
 
   - Discussion of removing timezone conversion
   5. http://mysql-python.sourceforge.net/MySQLdb.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/c7305bb1-097b-439b-8027-cb91f85c15aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to