Opened 16 years ago
Closed 16 years ago
#8218 closed (worksforme)
extra() with params and filter() does not return results
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | extra filter params | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm seeing some strange behavior with the latest 1.0 alpha when using extra() with params and filter(). Here is an example based on the Polls app created in the tutorial.
>>> from mysite.polls.models import Poll, Choice >>> p = Poll(question="What's up?", pub_date=datetime.datetime.now()) >>> p.save() >>> polls = Poll.objects.extra(select={'blah': 'select count(*) from polls_poll where id=%s'}, params=[1]) >>> [p for p in polls] [<Poll: Poll object>] >>> [p.blah for p in polls] [1]
Looks good so far, but as soon as I add a filter() to it that should return results, I get none:
>>> polls = Poll.objects.extra(select={'blah': 'select count(*) from polls_poll where id=%s'}, params=[1]) >>> polls = polls.filter(question="What's up?") >>> [p for p in polls] []
Note that the filter by itself works fine:
>>> polls = Poll.objects.filter(question="What's up?") >>> [p for p in polls] [<Poll: Poll object>]
If I take out the extra() params it also works ok:
>>> polls = Poll.objects.extra(select={'blah': 'select count(*) from polls_poll where id=1'}) >>> polls = polls.filter(question="What's up?") >>> [p for p in polls] [<Poll: Poll object>] >>> [p.blah for p in polls] [1]
It's only when I combine with an extra() AND params that the problem shows up. I am using sqlite3. Thanks.
Change History (3)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
You're using the extra()
method incorrectly. Passing parameters to an extra select should be done with the select_params
parameter, not params
.
If you fix your use of extra()
does the problem go away? If not, what does the SQL look like for the query (you can view that by doing Poll.objects.extra(...).filter(...).query.as_sql()
)?
comment:3 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Indeed select_params works. Thanks!
Is this the same as #8191 ?