querying DateTimeFields using the "in" query fails under sqlite
|Reported by:||mhalle@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Severity:||Keywords:||DateTimeField, in, SQLite|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When using the "in" query with a DateTimeField (in this case, DateField) with the SQLite backend, Django throws a TypeError. It doesn't matter whether the argument is a string or a datetime object. The same field can successfully be queried with the "range" query.
I didn't have time to look at the offending library code completely, but the problem appears to be a tuple vs. string/string character bug.
Traceback (most recent call last): File "querytst.py", line 14, in <module> print Complaint.objects.filter(incident_date__in=[datetime(2008, 2, 14)]).count() File "/Library/Python/2.5/site-packages/django/db/models/query.py", line 243, in count cursor.execute("SELECT COUNT(*)" + sql, params) File "/Library/Python/2.5/site-packages/django/db/backends/util.py", line 21, in execute sql = self.db.ops.last_executed_query(self.cursor, sql, params) File "/Library/Python/2.5/site-packages/django/db/backends/__init__.py", line 150, in last_executed_query return smart_unicode(sql) % u_params TypeError: not all arguments converted during string formatting
Change History (3)
comment:1 Changed 7 years ago by cgrady
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted