#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 Simon Charette):
You don't need this patch at all of the `save()` shenanigans. All you are doing here is circumventing the fact that must specify a language configuration for `ts_vector` to be immutable by running the `update(search_vector=self.search_vector)` that will use the session configured `default_text_search_config`. You can simply do {{{#!python class Document(models.Model): title = models.CharField(max_length=255) metadata = models.JSONField(null=True) class Meta: indexes = [ GinIndex( SearchVector('title', Coalesce('metadata', Value('')), config='english'), name='document_search', ), ] }}} Or use a `GeneratedField` if you want to materialize the search vector {{{#!python class Document(models.Model): title = models.CharField(max_length=255) metadata = models.JSONField(null=True) search_vector = GeneratedField( SearchVector('title', Coalesce('metadata', Value('')), config='english') output_field=SearchVectorField() ) class Meta: indexes = [ GinIndex( 'search_vector', name='search_vector_idx' ), ] }}} The key part here is that **a `config` must be specified if you want to use `SearchVector` in an index or generated field to make it `IMMUTABLE`** -- Ticket URL: <https://code.djangoproject.com/ticket/35539#comment:5> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107019097d04af7-7e096930-a512-42e1-af4c-7d66a186040d-000000%40eu-central-1.amazonses.com.