summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorGastón Avila <avila.gas@gmail.com>2024-09-04 17:32:40 -0300
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-09-11 14:36:56 +0200
commitc3ca6075cc0ad425bcf905fe14062f38eb9fbcbf (patch)
treede7bdb8aa20ef8916d48dfe434de32286601b978 /tests/postgres_tests
parent38c206515494cb28c48f77c10145a8aa9a172629 (diff)
Fixed #35732 -- Wrapped ConcatPair expression in parentheses to ensure operator precedence.
When ConcatPair was updated to use || this lost the implicit wrapping from CONCAT(...). This broke the WHERE clauses when used in combination with PostgreSQL trigram similarity. Regression in 6364b6ee1071381eb3a23ba6b821fc0d6f0fce75. Co-authored-by: Emiliano Cuenca <106986074+emicuencac@users.noreply.github.com>
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_trigram.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_trigram.py b/tests/postgres_tests/test_trigram.py
index 812403a324..b6c88c38a6 100644
--- a/tests/postgres_tests/test_trigram.py
+++ b/tests/postgres_tests/test_trigram.py
@@ -1,3 +1,6 @@
+from django.db.models import F, Value
+from django.db.models.functions import Concat
+
from . import PostgreSQLTestCase
from .models import CharFieldModel, TextFieldModel
@@ -149,6 +152,21 @@ class TrigramTest(PostgreSQLTestCase):
],
)
+ def test_trigram_concat_precedence(self):
+ search_term = "im matthew"
+ self.assertSequenceEqual(
+ self.Model.objects.annotate(
+ concat_result=Concat(
+ Value("I'm "),
+ F("field"),
+ output_field=self.Model._meta.get_field("field"),
+ ),
+ )
+ .filter(concat_result__trigram_similar=search_term)
+ .values("field"),
+ [{"field": "Matthew"}],
+ )
+
class TrigramTextFieldTest(TrigramTest):
"""