summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <simon.charette@zapier.com>2019-04-19 02:39:25 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-04-23 08:32:36 +0200
commit88bf635c356b4d3a47e88dc4142b90060ce3c2ef (patch)
tree643ff97dd1a497c6606078c195f8fdcbe11a8bf0 /tests
parent47885278c669dd7a13a4c3ff7e58e1cbe88af385 (diff)
[2.2.x] Fixed #30385 -- Restored SearchVector(config) immutability.
Regression in 1a28dc3887e8d66d5e3ff08cf7fb0a6212b873e5. The usage of CONCAT to allow SearchVector to deal with non-text fields made the generated expression non-IMMUTABLE which prevents a functional index to be created for it. Using a combination of COALESCE and ::text makes sure the expression preserves its immutability. Refs #29582. Thanks Andrew Brown for the report, Nick Pope for the review. Backport of 405c8363362063542e9e79beac53c8437d389520 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/postgres_tests/test_search.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py
index 303f4d8783..8944c6342d 100644
--- a/tests/postgres_tests/test_search.py
+++ b/tests/postgres_tests/test_search.py
@@ -8,6 +8,7 @@ transcript.
from django.contrib.postgres.search import (
SearchQuery, SearchRank, SearchVector,
)
+from django.db import connection
from django.db.models import F
from django.test import SimpleTestCase, modify_settings, skipUnlessDBFeature
@@ -346,6 +347,23 @@ class TestRankingAndWeights(GrailTestData, PostgreSQLTestCase):
self.assertSequenceEqual(searched, [self.verse0])
+class SearchVectorIndexTests(PostgreSQLTestCase):
+ def test_search_vector_index(self):
+ """SearchVector generates IMMUTABLE SQL in order to be indexable."""
+ # This test should be moved to test_indexes and use a functional
+ # index instead once support lands (see #26167).
+ query = Line.objects.all().query
+ resolved = SearchVector('id', 'dialogue', config='english').resolve_expression(query)
+ compiler = query.get_compiler(connection.alias)
+ sql, params = resolved.as_sql(compiler, connection)
+ # Indexed function must be IMMUTABLE.
+ with connection.cursor() as cursor:
+ cursor.execute(
+ 'CREATE INDEX search_vector_index ON %s USING GIN (%s)' % (Line._meta.db_table, sql),
+ params,
+ )
+
+
class SearchQueryTests(SimpleTestCase):
def test_str(self):
tests = (