Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django IPython sqlite complains about naive datetime

I have a new project in Django 1.4, using sqlite db. Also using django_extenstions' shell_plus with no problems.

When I installed IPython, both shell and shell_plus started to complain about:

/path/to/my/virtualenv/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:50:
RuntimeWarning: SQLite received a naive datetime (2012-07-29 13:15:45.229464) while time zone support is active.

It seems IPython itself uses unaware datetimes. How can this be fixed?

EDIT:

I don't want to disable Django's timezone support.

like image 851
frnhr Avatar asked Jul 29 '12 11:07

frnhr


2 Answers

I put this in my local_settings.py:

#ignore the following error when using ipython:
#/django/db/backends/sqlite3/base.py:50: RuntimeWarning:
#SQLite received a naive datetime (2012-11-02 11:20:15.156506) while time zone support is active.

import warnings
import exceptions
warnings.filterwarnings("ignore", category=exceptions.RuntimeWarning, module='django.db.backends.sqlite3.base', lineno=53)
like image 191
powlo Avatar answered Sep 23 '22 09:09

powlo


I have the same issue but I don't think that it's really a problem. IPython seems to use naive datetimes internally and Django just warns about it. Django always sends this warning when you turn on timezone support and whenever it detects a naive datetime. On my machine, this warning only appears when I start or close IPython. This warning does not influence your work with IPython in any way. So you can safely create aware datetimes normally inside IPython and also save them to your database. In order to get rid of that warning, you probably would have to work on IPython's internals.

When working with aware datetimes in general, I strongly recommend to use pytz for this purpose.

like image 42
pemistahl Avatar answered Sep 21 '22 09:09

pemistahl