#35539: SearchVector GinIndex raises IMMUTABLE error
----------------------------------+------------------------------------
Reporter: Alastair D'Silva | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Alastair D'Silva):
Having the NULL propagate doesn't seem to big deal when searching, it
still means that items that don't have a populated search vector won't be
found.
I have the following patch which is working for me, but does need a bit
more effort, in particular, the bit which removes to_tsvector if we
already have a ts_vector (you can't call to_tsvector on a ts_vector).
{{{
--- search.py.orig 2024-07-09 15:10:14.092901831 +1000
+++ search.py 2024-07-09 09:46:15.962716177 +1000
@@ -4,6 +4,7 @@
Field,
FloatField,
Func,
+ JSONField,
Lookup,
TextField,
Value,
@@ -113,19 +114,26 @@
def as_sql(self, compiler, connection, function=None, template=None):
clone = self.copy()
- clone.set_source_expressions(
- [
- Coalesce(
+
+ new_expressions = []
+ for expression in clone.get_source_expressions():
+ if isinstance(expression.output_field, SearchVectorField):
+ new_expressions.append(expression)
+ function = ''
+ elif isinstance(expression.output_field, JSONField):
+ new_expressions.append(Coalesce(expression,
Value("{}"))),
+ else:
+ new_expressions.append(Coalesce(
(
expression
if isinstance(expression.output_field,
(CharField, TextField))
else Cast(expression, TextField())
),
Value(""),
- )
- for expression in clone.get_source_expressions()
- ]
- )
+ ))
+
+ clone.set_source_expressions(new_expressions)
+
config_sql = None
config_params = []
if template is None:
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35539#comment:4>
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/0107019095e891e3-3f883e4d-48d6-4b1c-9f39-90d0c563c0a2-000000%40eu-central-1.amazonses.com.