Opened 7 years ago

Closed 7 years ago

#27896 closed Bug (worksforme)

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

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 Tim Graham)

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 (3)

comment:1 by David Black, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Component: UncategorizedDatabase layer (models, ORM)
Description: modified (diff)

I can't reproduce -- I see two passing tests with the sample project. Is the issue a regression from Django 1.9? If not, it probably doesn't qualify for a fix at this point. The latest possible bugfix release for 1.10 is April 1. By the way, please always use the latest bugfix release (1.10.6 as of now).

comment:3 by Tim Graham, 7 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top