[Django] #34079: Excessive parentheses when generating a query

15 views
Skip to first unread message

Django

unread,
Oct 9, 2022, 12:17:58 PM10/9/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-----------------------------------------+------------------------
Reporter: Lelikov | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
ORM:
{{{
Model.objects.filter(field=Func(F("user__notification_email_types"),
function="ANY")
}}}

SQL:
{{{
..."app_model"."filed" = (ANY("app_user"."notification_email_types")))
}}}

Error:
{{{
syntax error at or near "ANY"
}}}

The reason for the code change in version 4.0. The excessive parentheses
around the function ANY
django/db/models/lookups.py
{{{
if sql and sql[0] != "(":
sql = "(%s)" % sql
}}}
In version 3.2 everything worked correctly

--
Ticket URL: <https://code.djangoproject.com/ticket/34079>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 9, 2022, 12:18:16 PM10/9/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-------------------------------+--------------------------------------
Reporter: Lelikov | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Lelikov):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/34079#comment:1>

Django

unread,
Oct 9, 2022, 7:07:28 PM10/9/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-------------------------------+--------------------------------------
Reporter: Lelikov | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Giebisch):

Im pretty sure I had a similar error a few weeks ago. I can't test right
now, but if the error still persists, I will be happy to look into it :)

--
Ticket URL: <https://code.djangoproject.com/ticket/34079#comment:2>

Django

unread,
Oct 11, 2022, 9:45:09 AM10/11/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-------------------------------+--------------------------------------
Reporter: Lelikov | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Aman Pandey):

i would like to look into it

--
Ticket URL: <https://code.djangoproject.com/ticket/34079#comment:3>

Django

unread,
Oct 11, 2022, 9:45:16 AM10/11/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-------------------------------+---------------------------------------
Reporter: Lelikov | Owner: Aman Pandey
Type: Bug | Status: assigned

Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Aman Pandey):

* owner: nobody => Aman Pandey
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34079#comment:4>

Django

unread,
Oct 12, 2022, 7:05:42 AM10/12/22
to django-...@googlegroups.com
#34079: Excessive parentheses when generating a query
-------------------------------------+-------------------------------------

Reporter: Lelikov | Owner: Aman
| Pandey
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Peter Lithammer, Simon Charette (added)
* resolution: => invalid
* status: assigned => closed
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for the report, however this behavior was intentionally changed in
170b006ce82b0ecf26dc088f832538b747ca0115 (see also #32673) and we cannot
revert it without reintroducing regressions.

As far as I'm aware,`ANY` requires `ARRAY` or a subquery on the right-hand
side, so I'm not sure how this could work for you 🤔 Nevertheless you can
always creating a custom lookup, the following example works for me:
{{{#!python
class Any(Lookup):
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
params = (*lhs_params, *rhs_params)
return "%s = ANY(%s)" % (lhs, rhs), params

> Note.objects.filter(Any(F("note"),
Subquery(Annotation.objects.values("name"))))
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34079#comment:5>

Reply all
Reply to author
Forward
0 new messages