Code

Opened 6 years ago

Closed 6 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:

Description

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

Attachments (0)

Change History (3)

comment:1 Changed 6 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 6 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 6 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.