Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#3190 closed defect (duplicate)

Empty list in an "in"-lookup leads to a ProgrammingError

Reported by: Thomas Steinacher <tom@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: tom@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This code leads to a ProgrammingError instead of returning an empty QuerySet:

>>> models.FooBar.objects.filter(pk__in=[])
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 97, in __repr__
    return repr(self._get_data())
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 430, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 172, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
  File "/usr/lib/python2.4/site-packages/django/db/backends/", line 12, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/", line 42, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 137, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 33, in defaulterrorhandler
    raise errorclass, errorvalue
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1")

I'm using MySQL and Django SVN.

Change History (1)

comment:1 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Resolution: duplicate
Status: newclosed

dup of #2473.

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