summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLouise Grandjonc <louve.grandjonc@gmail.com>2019-10-01 16:25:40 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-11 10:55:22 +0200
commit7d1bf29977bb368d7c28e7c6eb146db3b3009ae7 (patch)
tree47ffb85fe9e1bc38c23a8bb532c587d82b15c95d /tests
parent6a75cea76a98c08bf2e20d787be9b14c2cd94860 (diff)
Fixed #30826 -- Fixed crash of many JSONField lookups when one hand side is key transform.
Regression in 6c3dfba89215fc56fc27ef61829a6fff88be4abb.
Diffstat (limited to 'tests')
-rw-r--r--tests/postgres_tests/test_json.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index 39cba8f695..956304d6f5 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -135,7 +135,12 @@ class TestQuerying(PostgreSQLTestCase):
'k': True,
'l': False,
}),
- JSONModel(field={'foo': 'bar'}),
+ JSONModel(field={
+ 'foo': 'bar',
+ 'baz': {'a': 'b', 'c': 'd'},
+ 'bar': ['foo', 'bar'],
+ 'bax': {'foo': 'bar'},
+ }),
])
def test_exact(self):
@@ -386,6 +391,26 @@ class TestQuerying(PostgreSQLTestCase):
queries[0]['sql'],
)
+ def test_lookups_with_key_transform(self):
+ tests = (
+ ('field__d__contains', 'e'),
+ ('field__baz__contained_by', {'a': 'b', 'c': 'd', 'e': 'f'}),
+ ('field__baz__has_key', 'c'),
+ ('field__baz__has_keys', ['a', 'c']),
+ ('field__baz__has_any_keys', ['a', 'x']),
+ ('field__contains', KeyTransform('bax', 'field')),
+ (
+ 'field__contained_by',
+ KeyTransform('x', RawSQL('%s::jsonb', ['{"x": {"a": "b", "c": 1, "d": "e"}}'])),
+ ),
+ ('field__has_key', KeyTextTransform('foo', 'field')),
+ )
+ for lookup, value in tests:
+ with self.subTest(lookup=lookup):
+ self.assertTrue(JSONModel.objects.filter(
+ **{lookup: value},
+ ).exists())
+
@isolate_apps('postgres_tests')
class TestChecks(PostgreSQLSimpleTestCase):