Opened 8 years ago

Closed 8 years ago

#6922 closed (duplicate)

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
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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 "", 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/", line 243, in count
    cursor.execute("SELECT COUNT(*)" + sql, params)
  File "/Library/Python/2.5/site-packages/django/db/backends/", 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/", 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 8 years ago by cgrady

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

in r7631, I'm not getting an exception doing this in sqlite, but it does seem to be failing silently:

>>> Bar.objects.filter(b__in=[date(2008, 6, 9), date(2008, 6, 10), date(2008, 6, 12)])
>>> connection.queries

so there definitely seems to be something wrong

comment:2 Changed 8 years ago by cgrady

  • Triage Stage changed from Accepted to Unreviewed

sorry, this appears to be completely different, as its happening in mysql also

the bug in this ticket may be fixed due to qsrf

comment:3 Changed 8 years ago by Karen Tracey <kmtracey@…>

  • Resolution set to duplicate
  • Status changed from new to closed

Cannot recreate the original TypeError using sqlite on r7877; the general problem of in lookups not working is covered by #7448.

Note: See TracTickets for help on using tickets.
Back to Top