Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#15836 closed Bug (duplicate)

Raw query documentation indicates wrong type for params

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

15836.patch (709 bytes ) - added by Aymeric Augustin 14 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Aymeric Augustin, 14 years ago

Easy pickings: unset
Triage Stage: UnreviewedAccepted

There are two ways to fix this:

  • accept both lists and tuples: I think that is what Django does in several places, attached patch implements this
  • change the docs

by Aymeric Augustin, 14 years ago

Attachment: 15836.patch added

comment:2 by Jacob, 14 years ago

milestone: 1.4
Triage Stage: AcceptedReady for checkin

comment:3 by Jacob, 14 years ago

Needs tests: set
Triage Stage: Ready for checkinAccepted

Er, wait, no it's not - needs a quick test first.

comment:4 by Aymeric Augustin, 14 years ago

Resolution: duplicate
Status: newclosed

This ticket was actually a duplicate of #14729 and it was fixed at r16088.

comment:5 by Jacob, 13 years ago

milestone: 1.4

Milestone 1.4 deleted

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