diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-05 19:34:16 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-06 13:33:13 +0200 |
| commit | db49def5fc03757048d6725097d4c3da44e7ea84 (patch) | |
| tree | 26633c0feb83bc0c3b7845d31d8254a24096c0e6 | |
| parent | dece89df81c30f917162b13277b71fca13d9a2a3 (diff) | |
[4.2.x] Fixed #34459 -- Fixed SearchVector() crash for parameters with % symbol.
Thanks Patryk Zawadzki for the report.
Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.
Backport of 4bf4222010fd8e413963c6c873e4088614332ef9 from main
| -rw-r--r-- | django/contrib/postgres/search.py | 5 | ||||
| -rw-r--r-- | docs/releases/4.2.1.txt | 4 | ||||
| -rw-r--r-- | tests/postgres_tests/test_search.py | 6 |
3 files changed, 11 insertions, 4 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py index 4e370aa167..936709c2f8 100644 --- a/django/contrib/postgres/search.py +++ b/django/contrib/postgres/search.py @@ -144,10 +144,7 @@ class SearchVector(SearchVectorCombinable, Func): weight_sql, extra_params = compiler.compile(clone.weight) sql = "setweight({}, {})".format(sql, weight_sql) - # These parameters must be bound on the client side because we may - # want to create an index on this expression. - sql = connection.ops.compose_sql(sql, config_params + params + extra_params) - return sql, [] + return sql, config_params + params + extra_params class CombinedSearchVector(SearchVectorCombinable, CombinedExpression): diff --git a/docs/releases/4.2.1.txt b/docs/releases/4.2.1.txt index 2dd051b8fa..c768b98b18 100644 --- a/docs/releases/4.2.1.txt +++ b/docs/releases/4.2.1.txt @@ -11,3 +11,7 @@ Bugfixes * Fixed a regression in Django 4.2 that caused a crash of ``QuerySet.defer()`` when deferring fields by attribute names (:ticket:`34458`). + +* Fixed a regression in Django 4.2 that caused a crash of + :class:`~django.contrib.postgres.search.SearchVector` function with ``%`` + characters (:ticket:`34459`). diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py index fa7d885221..6f6318899c 100644 --- a/tests/postgres_tests/test_search.py +++ b/tests/postgres_tests/test_search.py @@ -160,6 +160,12 @@ class SearchVectorFieldTest(GrailTestData, PostgreSQLTestCase): ) self.assertNotIn("COALESCE(COALESCE", str(searched.query)) + def test_values_with_percent(self): + searched = Line.objects.annotate( + search=SearchVector(Value("This week everything is 10% off")) + ).filter(search="10 % off") + self.assertEqual(len(searched), 9) + class SearchConfigTests(PostgreSQLSimpleTestCase): def test_from_parameter(self): |
