mirror of
https://github.com/django/django.git
synced 2024-12-25 18:46:22 +00:00
[4.2.x] Fixed #34459 -- Fixed SearchVector() crash for parameters with % symbol.
Thanks Patryk Zawadzki for the report. Regression in09ffc5c121
. Backport of4bf4222010
from main
This commit is contained in:
parent
dece89df81
commit
db49def5fc
@ -144,10 +144,7 @@ class SearchVector(SearchVectorCombinable, Func):
|
|||||||
weight_sql, extra_params = compiler.compile(clone.weight)
|
weight_sql, extra_params = compiler.compile(clone.weight)
|
||||||
sql = "setweight({}, {})".format(sql, weight_sql)
|
sql = "setweight({}, {})".format(sql, weight_sql)
|
||||||
|
|
||||||
# These parameters must be bound on the client side because we may
|
return sql, config_params + params + extra_params
|
||||||
# want to create an index on this expression.
|
|
||||||
sql = connection.ops.compose_sql(sql, config_params + params + extra_params)
|
|
||||||
return sql, []
|
|
||||||
|
|
||||||
|
|
||||||
class CombinedSearchVector(SearchVectorCombinable, CombinedExpression):
|
class CombinedSearchVector(SearchVectorCombinable, CombinedExpression):
|
||||||
|
@ -11,3 +11,7 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a regression in Django 4.2 that caused a crash of ``QuerySet.defer()``
|
* Fixed a regression in Django 4.2 that caused a crash of ``QuerySet.defer()``
|
||||||
when deferring fields by attribute names (:ticket:`34458`).
|
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`).
|
||||||
|
@ -160,6 +160,12 @@ class SearchVectorFieldTest(GrailTestData, PostgreSQLTestCase):
|
|||||||
)
|
)
|
||||||
self.assertNotIn("COALESCE(COALESCE", str(searched.query))
|
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):
|
class SearchConfigTests(PostgreSQLSimpleTestCase):
|
||||||
def test_from_parameter(self):
|
def test_from_parameter(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user