Opened 16 years ago

Closed 15 years ago

Last modified 14 years ago

#4002 closed (invalid)

Attributes added by extra() aren't visible to filter()

Reported by: exogen@… 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


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) (2.5 KB) - added by exogen@… 16 years ago.
extra / filter shortcoming demo

Download all attachments as: .zip

Change History (9)

comment:1 Changed 16 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedAccepted

Can you attach a short test/example code to help us track this down?

comment:2 Changed 16 years ago by exogen@…

I added a with a function that demonstrates the behavior. Drop it into any example app, syncdb, import and run the function.

Changed 16 years ago by exogen@…

Attachment: added

extra / filter shortcoming demo

comment:3 Changed 15 years ago by Malcolm Tredinnick

Keywords: qs-rf added

comment:4 Changed 15 years ago by Adrian Holovaty

Good catch.

comment:5 Changed 15 years ago by Malcolm Tredinnick

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 Changed 15 years ago by Malcolm Tredinnick

Keywords: qs-rf-fixed removed
Resolution: invalid
Status: newclosed

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.

comment:7 Changed 15 years ago by Malcolm Tredinnick

(In [6961]) queryset-refactor: Reverted [6762] because it generates invalid SQL. It only worked accidentally with SQLite.

Refs #4002.

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