Re: [Django] #36152: Annotation with `%` in alias fails at db level on Postgres and MySQL (was: Annotation with `%` in alias fails at db level on postgres)

4 views
Skip to first unread message

Django

unread,
Jan 28, 2025, 12:45:55 PM1/28/25
to django-...@googlegroups.com
#36152: Annotation with `%` in alias fails at db level on Postgres and MySQL
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* summary: Annotation with `%` in alias fails at db level on postgres =>
Annotation with `%` in alias fails at db level on Postgres and MySQL

Comment:

> Do we need to worry about a deprecation path for non-postgres backends?

I assume we would need a path yes, it's also crashing on MySQL though so
not only a problem on Postgres

{{{#!python
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/MySQLdb/cursors.py", line
200, in _mogrify
query = query % args
~~~~~~^~~~~~
TypeError: not enough arguments for format string

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/django/source/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/django/source/django/db/backends/mysql/base.py", line 76, in
execute
return self.cursor.execute(query, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/MySQLdb/cursors.py", line
176, in execute
mogrified_query = self._mogrify(query, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/MySQLdb/cursors.py", line
202, in _mogrify
raise ProgrammingError(str(m))
MySQLdb.ProgrammingError: not enough arguments for format string
}}}

The specialized logic for Oracle originated from
2249bd275cbae6b73716bf36f5f36def1bb4222e which was likely to support
introspecting legacy tables columns containing `%` signs. Tat means we
can't realistically deprecate the `quote_name` path entirely. I haven't
looked into why things work on SQLite.
--
Ticket URL: <https://code.djangoproject.com/ticket/36152#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages