#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
-----------------------------------------+------------------------
               Reporter:  David Black    |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Uncategorized  |        Version:  1.10
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 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/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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27896>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.58ddc269cb6c185f6a9eedd8a366d37c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to