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.
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #25705
--
Ticket URL: <https://code.djangoproject.com/ticket/33746#comment:1>