Opened 6 years ago

Closed 6 years ago

#14110 closed (wontfix)

iexact lookup doesn't work with subquery values

Reported by: Alexander Schepanovski Owned by: Alexander Schepanovski
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:


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 Alexander Schepanovski 6 years ago.

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by Alexander Schepanovski

Attachment: where.cast.diff added

comment:1 Changed 6 years ago by Alexander Schepanovski

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 6 years ago by aweakley

Keywords: sprintdec2010 added
Resolution: wontfix
Status: newclosed

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.

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