Code

Opened 4 years ago

Closed 3 years ago

#14110 closed (wontfix)

iexact lookup doesn't work with subquery values

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

Description

With PostgreSQL and model

class Category(models.Model):
    title = models.CharField(max_length=127)

we have:

>>> Category.objects.filter(title__icontains=Category.objects.filter(pk=1).values('title'))
DatabaseError: syntax error at or near "("
LINE 1: ...PPER("board_category"."title"::text) LIKE UPPER() (SELECT U0...

>>> print connection.queries[-1]['sql']
SELECT "app_category"."id", "app_category"."title" FROM "app_category" WHERE UPPER("app_category"."title"::text)
LIKE UPPER() (SELECT U0."title" FROM "app_category" U0 WHERE U0."id" = 1 )

problem with every lookup for which %s is in the middle of connection.operators[lookup]

Attachments (1)

where.cast.diff (948 bytes) - added by Suor 4 years ago.

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by Suor

comment:1 Changed 4 years ago by Suor

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

P.S. supplied patch doesn't make it right for icontains but it will do for iexact for postgre and many lookups for oracle.

Also, current code assume that connection.operators[lookup] will end with %s which is wrong.

comment:2 Changed 3 years ago by aweakley

  • Keywords sprintdec2010 added
  • Resolution set to wontfix
  • Status changed from new to closed

I ran this past Russ.
This seems like very much an edge case, relying on the fact that a one-item values result could be interpreted as a string.

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.