#35539: contrib/postgres/search.py COALESCE breaks GIN Index creation on PostgreSQL
15
--------------------------------------------+------------------------
Reporter: deece | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
I have a Document model with the following subclass:
{{{
class Meta:
indexes = [
GinIndex(SearchVector('search_vector'), name='Document search
vector'), # Create a GIN index on the search vector
]
}}}
It creates the following migration:
{{{
migrations.AddIndex(
model_name='document',
index=django.contrib.postgres.indexes.GinIndex(django.contrib.postgres.search.SearchVector('search_vector'),
name='Document search vector'),
),
}}}
which in turn attempts to create the following index:
{{{
CREATE INDEX "Document search vector" ON "documents_document" USING gin
((to_tsvector(COALESCE(("search_vector")::text, ''))))
}}}
This fails with:
{{{
ERROR: functions in index expression must be marked IMMUTABLE
}}}
If I update contrib/postgres/search.py as follows:
91:
{{{
function = ""
}}}
and 116-128:
{{{
# clone.set_source_expressions(
# [
# Coalesce(
# (
# expression
# if isinstance(expression.output_field,
(CharField, TextField))
# else Cast(expression, TextField())
# ),
# Value(""),
# )
# for expression in clone.get_source_expressions()
# ]
# )
}}}
I can successfully create the index, and searches using SearchRank
successfully use it.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35539>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.