Opened 8 years ago

Last modified 8 years ago

#27896 closed Bug

In Django 1.10 when sqlite is used and TIME_ZONE=None a django.db.utils.OperationalError error is raised when filtering by __date on a DateTimeField — at Initial Version

Reported by: David Black Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Django 1.10 when sqlite is used and TIME_ZONE=None a django.db.utils.OperationalError error is raised when filtering by date on a DateTimeField.

For example,

ExampleModel.objects.filter(created_date__date=a_date).exists()

I have created a test project on github to demonstrate this issue which can be found at https://github.com/dbaxa/django-sqlite-datetime-bug .

Creating test database for alias 'default'...
.E
======================================================================
ERROR: test_filter_using__date_not_none_time_zone (example.tests.TestExampleModel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: user-defined function raised exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/victim/hacking/django-sqlite-bug-example/sqlite_datetime_bug/example/tests.py", line 24, in test_filter_using__date_not_none_time_zone
    self.shared_test()
  File "/home/victim/hacking/django-sqlite-bug-example/sqlite_datetime_bug/example/tests.py", line 20, in shared_test
    self.assertTrue(results.exists())
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/query.py", line 660, in exists
    return self.query.has_results(using=self.db)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/sql/query.py", line 494, in has_results
    return compiler.has_results()
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 806, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/victim/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: user-defined function raised exception

----------------------------------------------------------------------
Ran 2 tests in 0.024s

FAILED (errors=1)
Destroying test database for alias 'default'...

This issue does not affect Django 1.11 as it does not allow TIME_ZONE to be set to None.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top