On Fri, Nov 16, 2012 at 5:50 PM, Sencha <mich...@d3i.com> wrote:
> Yes I'm aware of this, however I'm not generating the datetime objects, it's
> all coming from Django (hence me wondering whether or not it's a bug or
> not). All I need to do to replicate the bug is get the object from the db
> and then save is straight away; then warning appears.
>
> Django abstracts away the difference between MySQL's datetime field and
> timestamp field, so it should work!
>

Oh really? How have you determined that django is producing the naive
datetime? This is a loaded question, since I know django does not
produce naive datetimes when USE_TZ=True! See the end of the email for
the easiest way to determine where the naive datetime is actually
coming from.

All the purported solutions suggested in this thread have missed that
TZ support in django adds some nifty shortcuts, prime being
timezone.now():

https://docs.djangoproject.com/en/1.4/ref/utils/#django.utils.timezone.now

This will always DTRT, producing naive datetimes if USE_TZ is false,
and aware datetimes otherwise. You should replace everywhere you call
'datetime.now()' with 'timezone.now()', so that all your datetimes are
TZ aware.

I would thoroughly recommend re-reading the TZ docs. There is an
excellent migration guide, FAQs and troubleshooting hints (one of
which covers this exact issue):

https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/

The easiest way to determine where the naive time is coming from is to
turn the Warning into a RuntimeWarning, so that as soon as it happens
Django will explode and you will get a lovely traceback showing
precisely where it was created. Add this to your settings.py:

import warnings
warnings.filterwarnings(
        'error', r"DateTimeField received a naive datetime",
        RuntimeWarning, r'django\.db\.models\.fields')

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to