Opened 17 years ago

Closed 16 years ago

#5261 closed (fixed)

exclude on an empty Q object results in invalid SQL

Reported by: django@… Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: exclude Q, qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is a minor corner case, but as it results in invalid SQL, I figured it should be fixed.

sqlite3:

>>> Proposal.objects.exclude(Q())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".\django\db\models\query.py", line 107, in __repr__
    return repr(self._get_data())
  File ".\django\db\models\query.py", line 480, in _get_data
    self._result_cache = list(self.iterator())
  File ".\django\db\models\query.py", line 188, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
  File ".\django\db\backends\util.py", line 19, in execute
    return self.cursor.execute(sql, params)
  File ".\django\db\backends\sqlite3\base.py", line 94, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: near ")": syntax error
>>>

postgresql:

>>> Proposal.objects.exclude(Q())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".\django\db\models\query.py", line 107, in __repr__
    return repr(self._get_data())
  File ".\django\db\models\query.py", line 480, in _get_data
    self._result_cache = list(self.iterator())
  File ".\django\db\models\query.py", line 188, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
  File ".\django\db\backends\util.py", line 19, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: syntax error at or near ")"
LINE 1: ...l"."updated" FROM "propmgr_proposal" WHERE ((NOT ())) ORDER ...
                                                             ^

>>>

Change History (6)

comment:1 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf added
Triage Stage: UnreviewedAccepted

comment:2 by shsiung, 17 years ago

Owner: changed from nobody to shsiung

comment:3 by shsiung, 17 years ago

Owner: shsiung removed

comment:4 by Malcolm Tredinnick, 16 years ago

(In [6519]) queryset-refactor: Added a test to show that #5261 is no longer a problem. Refs #5261.

comment:5 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf-fixed added; qs-rf removed

comment:6 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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