Opened 7 years ago

Closed 7 years ago

#7111 closed (fixed)

Double negation in sql query fails on Oracle

Reported by: ikelly Owned by: ikelly
Component: Database layer (models, ORM) Version: master
Severity: Keywords: oracle
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In [3]: qs = Item.objects.exclude(~Q(tags__name='t1', name='one'))

In [4]: qs.query.as_sql()
Out[4]:
('SELECT "TEST_ITEM"."ID", "TEST_ITEM"."NAME", "TEST_ITEM"."CREATED", "TEST_ITEM"."CREATOR_ID", "TEST_ITEM"."NOTE_ID" FROM "TEST_ITEM" INNER JOIN "TEST_NOTE" ON ("TEST_ITEM"."NOTE_ID" = "TEST_NOTE"."ID") WHERE NOT NOT ("TEST_ITEM"."NAME" = %s  AND "TEST_ITEM"."ID" IN (SELECT "TEST_ITEM_TAGS"."ITEM_ID" FROM "TEST_ITEM_TAGS" INNER JOIN "TEST_TAG" ON ("TEST_ITEM_TAGS"."TAG_ID" = "TEST_TAG"."ID") WHERE "TEST_TAG"."NAME" = %s )) ORDER BY "TEST_NOTE"."NOTE" DESC, "TEST_ITEM"."NAME" ASC',
 ('one', 't1'))

This causes an error in Oracle because the "NOT NOT (condition)" syntax in the where clause is invalid. The syntax "NOT (NOT (condition))" would work.

Change History (3)

comment:1 Changed 7 years ago by ikelly

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

By the way, this query is lifted straight from the queries test.

comment:2 Changed 7 years ago by ikelly

  • Owner changed from nobody to ikelly
  • Status changed from new to assigned

comment:3 Changed 7 years ago by ikelly

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [7509]) Fixed an Oracle error on double negations in where conditions. Fixed #7111

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