2👍
The response is quite simple: I misinterpreted the problem.
The issue comes from an underlying problem: the MySQL LIKE
statement is case-sensitive or insensitive depending on the collation and the Django filter used (icontains
or contains
) has no effect in the outcome. You can see this bug ticket for more information.
As Daniel Roseman pointed out, the .query
property is not reliable, as the query is further processed by the database driver. This led me to believe that Django created a wrong query, while in fact it simply created a case-sensitive search that should have been case-insensitive, hence the lack of results.
In the end, the issue was resolved by changing the collation on columns, tables and the database.
Source:stackexchange.com