#15836 closed Bug (duplicate)
Raw query documentation indicates wrong type for params
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Documentation | Version: | 1.3 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Pretty trivial, but the documentation (and example) indicate that the raw() method takes params as a list. However, this results in an error (see steps to reproduce below). Tuples, rather, have to be used.
See: http://docs.djangoproject.com/en/1.3/topics/db/sql/#passing-parameters-into-raw
To reproduce:
>>> from django.contrib.auth.models import User
>>> User.objects.raw("SELECT * FROM auth_user WHERE id = %s AND username = '%s'", [1, 'test'])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/irf/htdocs/ourgroup/trunk/lib/python2.6/site-packages/django/db/models/query.py", line 1376, in __repr__
return "<RawQuerySet: %r>" % (self.raw_query % self.params)
TypeError: not enough arguments for format string
>>>
>>>
>>> User.objects.raw("SELECT * FROM auth_user WHERE id = %s AND username = '%s'", (1, 'test'))
<RawQuerySet: "SELECT * FROM auth_user WHERE id = 1 AND username = 'test'">
Platform:
Ubuntu 10.10 \n \l
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Attachments (1)
Change History (6)
comment:1 by , 15 years ago
| Easy pickings: | unset |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
by , 15 years ago
| Attachment: | 15836.patch added |
|---|
comment:2 by , 15 years ago
| milestone: | → 1.4 |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
comment:3 by , 15 years ago
| Needs tests: | set |
|---|---|
| Triage Stage: | Ready for checkin → Accepted |
Er, wait, no it's not - needs a quick test first.
comment:4 by , 15 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
There are two ways to fix this: