Opened 4 years ago

Closed 4 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: master
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


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/ in __repr__(self)
     85     def __repr__(self):
---> 86         return "<RawQuery: %r>" % (self.sql % tuple(self.params))
     88     def _execute_query(self):

TypeError: format requires a mapping

Change History (3)

comment:2 Changed 4 years ago by Baptiste Mispelon

Has patch: set
Triage Stage: UnreviewedAccepted


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).


comment:3 Changed 4 years ago by Tim Graham <timograham@…>

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