#4002 closed (invalid)
Attributes added by extra() aren't visible to filter()
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | extra filter | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Attributes added with the extra() method are visible by order_by, but not to filter. An exception is raised:
<type 'exceptions.TypeError'>: Cannot resolve keyword 'test' into field
...but order_by('test') works fine.
Attachments (1)
Change History (9)
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 18 years ago
I added a models.py with a function that demonstrates the behavior. Drop it into any example app, syncdb, import and run the function.
comment:3 by , 17 years ago
Keywords: | qs-rf added |
---|
comment:5 by , 17 years ago
Keywords: | qs-rf-fixed added; qs-rf removed |
---|
Fixed on queryset-refactor branch in [6762]. Will be closed when that branch is merged into trunk.
comment:6 by , 17 years ago
Keywords: | qs-rf-fixed removed |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Upon further reflection, this isn't a valid request. The SQL standard requires (and MySQL and PostgreSQL, at least, enforce) that the where-clause only refers to table columns, not aggregates or other computed columns. So you can't refer to extra_select things in the filtering phase. (The tests I committed above show the failure on those two backends. It's really just a fluke that SQLite works here.)
When we implement "GROUP BY" and "HAVING" support, the sort of thing you're trying to do here will be possible.
I'm going to commit a patch that reverts [6762] shortly.
Can you attach a short test/example code to help us track this down?