Opened 4 years ago

Closed 4 years ago

Last modified 4 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:

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 aaugustin 4 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

Changed 4 years ago by aaugustin

comment:2 Changed 4 years ago by jacob

  • milestone set to 1.4
  • Triage Stage changed from Accepted to Ready for checkin

comment:3 Changed 4 years ago by jacob

  • Needs tests set
  • Triage Stage changed from Ready for checkin to Accepted

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

comment:4 Changed 4 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed

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

comment:5 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

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