Code

Opened 6 years ago

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

Attachments (0)

Change History (3)

comment:1 Changed 6 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 6 years ago by ikelly

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

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

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.