Opened 10 years ago

Closed 10 years ago

#23313 closed Bug (fixed)

RawQuery.__repr__ fails when params passed as dict

Reported by: movEAX Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: raw query
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [1]: from django.db.models.sql.query import RawQuery

In [2]: raw_query = RawQuery('SELECT %(foo)s', None, {'foo': 'bar'})

In [3]: repr(raw_query)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-7fb02908cd64> in <module>()
----> 1 repr(raw_query)

/home/user/.src/django/django/db/models/sql/query.py in __repr__(self)
     84 
     85     def __repr__(self):
---> 86         return "<RawQuery: %r>" % (self.sql % tuple(self.params))
     87 
     88     def _execute_query(self):

TypeError: format requires a mapping

Change History (3)

comment:2 by Baptiste Mispelon, 10 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

Hi,

While RawQuery is an undocumented implementation detail, the issue you found still seems worth fixing (plus I think it's possible to trigger it using Queryset.raw() which is documented).

Thanks.

comment:3 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In bc06d2c11c32bde94b717a75bd3325ef1b94c902:

Fixed #23313 -- Corrected repr(RawQuery) with dict parameters.

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