﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27896	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	David Black	nobody	"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 .


  {{{#!python
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."	Bug	closed	Database layer (models, ORM)	1.10	Normal	worksforme			Unreviewed	0	0	0	0	0	0
