Django

Code

Ticket #5261 (closed: fixed)

Opened 9 months ago

Last modified 3 weeks ago

exclude on an empty Q object results in invalid SQL

Reported by: django@dougma,com Assigned to:
Component: Database wrapper Version: SVN
Keywords: exclude Q, qs-rf-fixed Cc:
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

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 ...
                                                             ^

>>>

Attachments

Change History

09/13/07 16:44:45 changed by mtredinnick

  • keywords changed from exclude Q to exclude Q, qs-rf.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

09/14/07 13:55:10 changed by shsiung

  • owner changed from nobody to shsiung.

09/14/07 14:52:35 changed by shsiung

  • owner deleted.

10/14/07 22:47:10 changed by mtredinnick

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

10/14/07 22:47:37 changed by mtredinnick

  • keywords changed from exclude Q, qs-rf to exclude Q, qs-rf-fixed.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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


Add/Change #5261 (exclude on an empty Q object results in invalid SQL)




Change Properties
Action