Opened 7 years ago

Last modified 7 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 Version 1

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 (last modified by David Black)

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/user/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/user/.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/user/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/user/django-sqlite-bug-example/sqlite_datetime_bug/example/tests.py", line 20, in shared_test
    self.assertTrue(results.exists())
  File "/home/user/.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/user/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/sql/query.py", line 494, in has_results
    return compiler.has_results()
  File "/home/user/.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/user/.virtualenvs/django/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "/home/user/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/user/.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/user/.virtualenvs/django/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/user/.virtualenvs/django/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/user/.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 (1)

comment:1 by David Black, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top