Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sub-expressions not wrapped by parentheses #2200

Closed
theosotr opened this issue Jun 9, 2020 · 1 comment
Closed

sub-expressions not wrapped by parentheses #2200

theosotr opened this issue Jun 9, 2020 · 1 comment

Comments

@theosotr
Copy link

theosotr commented Jun 9, 2020

I have the following query (simplified for opening issue):

expr = (Value(1) + Model.column)
squared = (expr * expr)
Model.select(fn.sum(expr), fn.avg(squared)).objects()

peewee generates the SQL query below

SELECT sum(1 + "t1"."column"), avg(1 + "t1"."column" * 1 + "t1"."column") FROM "model" AS "t1"

Notably, the sub-expressions in avg(1 + "t1"."column" * 1 + "t1"."column") are not wrapped by parentheses as expected. That is

SELECT sum(1 + "t1"."column"), avg((1 + "t1"."column") * (1 + "t1"."column")) FROM "model" AS "t1"
@coleifer
Copy link
Owner

coleifer commented Jun 9, 2020

Thanks for reporting. This bug was caused by modifying an internal flag on the expression node without copying it first. This caused subsequent usages of that expression node to carry-over the flag when they shouldn't have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants