Opened 14 years ago
Closed 14 years ago
#14729 closed Bug (fixed)
RawQuerySet.__repr__ fails when params passed as list
Reported by: | Marti Raudsepp | Owned by: | Alexey Smolsky |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2 |
Severity: | Normal | Keywords: | raw query |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | UI/UX: |
Description
Django 1.2.3. The documentation suggests passing arguments to a Model.objects.raw() query as a list: http://docs.djangoproject.com/en/dev/topics/db/sql/#passing-parameters-into-raw
However, this breaks RawQuerySet.repr
In [1]: from django.contrib.auth import models In [2]: r=models.User.objects.raw('select * from auth_user where id=%s', 10) In [3]: repr(r) Out[3]: "<RawQuerySet: 'select * from auth_user where id=10'>" In [4]: r=models.User.objects.raw('select * from auth_user where id=%s and id=%s', (10, 10)) In [5]: repr(r) Out[5]: "<RawQuerySet: 'select * from auth_user where id=10 and id=10'>" In [6]: r=models.User.objects.raw('select * from auth_user where id=%s and id=%s', [10, 10]) In [7]: repr(r) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/foo/<ipython console> in <module>() /usr/lib/pymodules/python2.6/django/db/models/query.pyc in __repr__(self) 1374 1375 def __repr__(self): -> 1376 return "<RawQuerySet: %r>" % (self.raw_query % self.params) 1377 1378 def __getitem__(self, k): TypeError: not enough arguments for format string
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
Has patch: | set |
---|---|
Keywords: | raw query added |
milestone: | → 1.3 |
Needs tests: | unset |
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 14 years ago
Version: | 1.2 → SVN |
---|
comment:4 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|---|
Version: | SVN → 1.2 |
Still applies correctly and fixes the reported problem.
Moving version back to 1.2 -- changing the version to SVN is not helpful because the field signifies since when a problem exists -- the fact that the ticket is still open already means that the problem still exists in SVN trunk.
Thanks!
comment:5 by , 14 years ago
milestone: | 1.3 |
---|---|
Severity: | → Normal |
Type: | → Bug |
As official python documentation says(http://docs.python.org/library/stdtypes.html#string-formatting-operations), not-single argument for string formatting operation must be tuple or dictionary. So, we need pass list argument as tuple.
Patch with tests attached above.