Opened 24 hours ago
Closed 8 hours ago
#36261 closed New feature (wontfix)
`icontains` lookup doesn't work with case insensitive collations
Description ¶
As recommended by django's warning messages when upgrading to 4.x we replaced our use of the CITEXT
db type with a case insensitive collation (specifically und-u-ks-level2
)
We have discovered that this prevents us from using search in the Django admin. The error we receive is
NotSupportedError: nondeterministic collations are not supported for LIKE
This makes sense since the collation cannot supprot case-sensitive comparison. However, django admin's search box is supposed to be case-insensitive. It explicitly uses icontains
.
It turns out that icontains
is implemented using UPPER(fieldname) LIKE UPPER(pattern)
. Some of this logic is here (although I'm not sure where the second UPPER gets added)
How to fix it?
- It seems that
icontains
(andiexact
etc) comparisons should useILIKE
, which would work fine in this situation. I have looked through git and ticket history and can't find any discussion of why it's implemented usingLIKE
instead.
- Alternatively, using
x LIKE y COLLATE "default"
seems to avoid the issue in this case, although someone who knows more about collations should probably weigh in on what other side-effects that might have...
Change History (2)
comment:2 by , 8 hours ago
Keywords: | collation added |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Type: | Bug → New feature |
Thank you, Craig, for the ticket report, and Simon for the additional context on PostgreSQL 18's improvements.
This issue has been previously discussed in this forum post, covering both LIKE
lookups and index creation challenges. Additionally, Adam Johnson's post provides a step-by-step guide to addressing these issues.
Given that PostgreSQL 18 is expected in September 2025 and Django 6.0's feature freeze is set for September 17, 2025, support for PostgreSQL 18 will likely land in Django 6.1. Therefore, I'm inclined to closing this as wontfix
for now. Any new findings can be shared in the referenced forum post, and if a clear implementation path emerges, I'd be happy to reopen this ticket.
Relevant article on the subject.
It appears that Postgres 18+ does support
LIKE
against nondeterministic collations so that should be taken into consideration when taking a decision here.Are you sure of that? It appears that
ILIKE
is explicitly pointed out as not being implemented for nondeterministic collation as it's unclear whether or not it makes sense.Some context for you
Not an expert but I think this might cause more harm than good as it basically ignore the specified collation on the column?
For anyone running into this problem you can register field instance lookups to work around the problem
Here's the fiddle I used to review this ticket.