google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Not returning timezone aware datetime objects when using Django 1.4 and USE_TZ option #122

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using Djano 1.4 
2. Apply patch provided in issue 120
3. pip install pytz
4. Set USE_TZ = True in settings.py.  Set TIME_ZONE in settings.py
5. run ./manage.py shell on an existing project.
6. import pytz
7. from django.conf import settings
8. from <your app>.models import <model with datetime field>
9. obj = <your model>.objects.all()[0]
10.obj.<datetime field>.astimezone(pytz.timezone(settings.TIME_ZONE))

What is the expected output? What do you see instead?
Expect a timezone corrected output.  Instead, see the error..
ValueError: astimezone() cannot be applied to a naive datetime.

What version of the product are you using? On what operating system?
Django 1.4
pyodbc 3.3
django-pyodbc r191
RHEL 6.2

Please provide any additional information below.

Django 1.4 expects timezone aware objects internally.  The mysql, postgres, 
oracle db backends were updated to convert naive datetimes coming from db reads 
to aware datetimes with a UTC stamp.  On writes, the dates created in the 
system timezone are converted back to UTC and timezone status removed before 
being sent to the db api.

Original issue reported on code.google.com by Rob.Ca...@quriousmobile.com on 13 Apr 2012 at 6:25

GoogleCodeExporter commented 9 years ago
Theoretically working fix defined by diff at 
https://github.com/robcavin/django-pyodbc/commit/827d2bd166b26b84d9eb92cf363db44
03b3af2fb.

Fork at git@github.com:robcavin/django-pyodbc.git

Original comment by Rob.Ca...@quriousmobile.com on 14 Apr 2012 at 2:37