HAVING filter screws with extra() SQL parameter ordering
|Reported by:||miracle2k||Owned by:|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||bas@…, shaunc@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
>>> qs = Model.objects.extra(where=['foo>%s'], params=).annotate(count=Count('bar')).filter(bar=99) >>> qs.query.as_sql() ('SELECT `site_publication`.`id`, ..., FROM ... WHERE foo > %s GROUP BY ... HAVING bar > %s', (99, 2))
As you can see, the parameters (99 and 2) are in the wrong order. "foo", the first filter, should be evaluated against 2, and bar, the second one, against 99.
If "bar" is not an aggregate, it works, because apparently the filter would be placed in the WHERE clause *before* the "extra()" where.
Using rev. 10743.
Change History (14)
comment:1 Changed 6 years ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 6 years ago by paluh
comment:11 Changed 3 years ago by akaariai
- Component changed from ORM aggregation to Database layer (models, ORM)
comment:12 Changed 2 months ago by timgraham
- Resolution set to wontfix
- Status changed from new to closed