Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25506 closed Bug (fixed)

Can't filter over a RawSQL annotation

Reported by: Antoine Catton Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords: RawSQL filter ORM sql
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here's the simplest test case for this bug:

>>> User.objects.annotate(foo=RawSQL('%s', ['value', ])).filter(foo__iexact='value')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../django/db/models/query.py", line 234, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File ".../django/db/models/query.py", line 258, in __iter__
    self._fetch_all()
  File ".../django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File ".../django/db/models/query.py", line 52, in __iter__
    results = compiler.execute_sql()
  File ".../django/db/models/sql/compiler.py", line 852, in execute_sql
    cursor.execute(sql, params)
  File ".../django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File ".../django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
TypeError: not all arguments converted during string formatting

I'm working on a fix https://github.com/django/django/pull/5396

Change History (4)

comment:1 by Tim Graham, 9 years ago

Severity: Release blockerNormal
Triage Stage: UnreviewedAccepted

comment:2 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In b971c1cd:

Fixed #25506 -- Allowed filtering over a RawSQL annotation.

Co-Authored-By: Gavin Wahl <gwahl@…>

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

In ee6785e:

[1.8.x] Fixed #25506 -- Allowed filtering over a RawSQL annotation.

Co-Authored-By: Gavin Wahl <gwahl@…>

Backport of b971c1cd78a0bf831c1c30080089c4a384d037a0 from master

comment:4 by Tim Graham <timograham@…>, 9 years ago

In 36e7d275:

[1.9.x] Fixed #25506 -- Allowed filtering over a RawSQL annotation.

Co-Authored-By: Gavin Wahl <gwahl@…>

Backport of b971c1cd78a0bf831c1c30080089c4a384d037a0 from master

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