Opened 18 years ago

Closed 17 years ago

Last modified 16 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

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)

models.py (2.5 KB ) - added by exogen@… 18 years ago.
extra / filter shortcoming demo

Download all attachments as: .zip

Change History (9)

comment:1 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedAccepted

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

comment:2 by exogen@…, 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.

by exogen@…, 18 years ago

Attachment: models.py added

extra / filter shortcoming demo

comment:3 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf added

comment:4 by Adrian Holovaty, 17 years ago

Good catch.

comment:5 by Malcolm Tredinnick, 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 Malcolm Tredinnick, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

(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