Opened 8 months ago

Closed 8 months 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

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:1 Changed 8 months ago by movEAX

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 months ago by bmispelon

  • Has patch set
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 8 months ago by Tim Graham <timograham@…>

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

In bc06d2c11c32bde94b717a75bd3325ef1b94c902:

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

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