#33746: [ORM] queryset.query return a string that makes MySQLDB to fail with
error
"not enough arguments for format string"
-------------------------------------+-------------------------------------
Reporter: Juanmi | Owner: nobody
Taboada |
Type: Bug | Status: new
Component: Database | Version: 4.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Recently I faced an error when getting a query with **queryset.query**.
The resultant string had inside "**%**" (percentage character) for **LIKES
clauses** and **MySQLDB** module at is actual version is rendering the
query using:
{{{
query = query % args
}}}
Example of the wrong a QUERY I got from **queryset.query** rendering:
{{{
SELECT DISTINCT products_becaseeker.beca_id,
`products_becaseeker`.`status` FROM `products_becaseeker` INNER JOIN
`products_becapublic` ON (`products_becaseeker`.`beca_id` =
`products_becapublic`.`beca_id`) WHERE
(`products_becapublic`.`convenor_id` = 246 OR
`products_becapublic`.`convenor_id` = 34 OR
LOWER(JSON_UNQUOTE(`products_becaseeker`.`convenor_others`)) LIKE
LOWER(%"246"%) OR
LOWER(JSON_UNQUOTE(`products_becaseeker`.`convenor_others`)) LIKE
LOWER(%"34"%)) AND MATCH(products_becaseeker.keywords) AGAINST
(\'(comunidad* madrid*) ("comunidad de madrid") ("comunidad de madrid")
(comunidad madrid)\' IN BOOLEAN MODE) ORDER BY products_becaseeker.status
DESC
}}}
the offending part is:
{{{
... LIKE LOWER(%"246"%) ...
... LIKE LOWER(%"34"%) ...
}}}
I believe the right string to be render in **MySQLDB** should be:
{{{
... LIKE LOWER("%%246%%") ...
... LIKE LOWER("%%34%%") ...
}}}
The error I verified it is happening in **Django 4.0.2** together with
**Python 3.9** at **MySQLdb/cursors.py, line 201**
The short quick solution was to replace those with the right ones:
{{{
.replace('(%"', '("%%').replace('"%)', '%%")')
}}}
and it worked like a charm, but I believe the query rendered should be
aware about how MySQLDB is rendering the query.
--
Ticket URL: <https://code.djangoproject.com/ticket/33746>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070181042ebccc-c10cd2a8-6742-497d-ab19-adf8593787a7-000000%40eu-central-1.amazonses.com.