Skip to content

Commit

Permalink
Fixed #34459 -- Fixed SearchVector() crash for parameters with % symbol.
Browse files Browse the repository at this point in the history
Thanks Patryk Zawadzki for the report.

Regression in 09ffc5c.
  • Loading branch information
felixxm committed Apr 6, 2023
1 parent ab4d71c commit 3fdd5fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions django/contrib/postgres/search.py
Expand Up @@ -144,10 +144,7 @@ def as_sql(self, compiler, connection, function=None, template=None):
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):
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/4.2.1.txt
Expand Up @@ -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`).
6 changes: 6 additions & 0 deletions tests/postgres_tests/test_search.py
Expand Up @@ -160,6 +160,12 @@ def test_single_coalesce_expression(self):
)
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):
Expand Down

0 comments on commit 3fdd5fe

Please sign in to comment.