From 7408c4cd157ae18971302a2baf7aacce7c204a09 Mon Sep 17 00:00:00 2001 From: sage Date: Wed, 25 Nov 2020 13:27:35 +0100 Subject: [PATCH] Refs #32203 -- Added tests for QuerySet.values()/values_list() on key transforms with non-trivial values. --- tests/model_fields/test_jsonfield.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py index 8bec000100..23479b4c0d 100644 --- a/tests/model_fields/test_jsonfield.py +++ b/tests/model_fields/test_jsonfield.py @@ -749,6 +749,19 @@ class TestQuerying(TestCase): expected, ) + def test_key_values(self): + qs = NullableJSONModel.objects.filter(value__h=True) + tests = [ + ('value__a', 'b'), + ('value__d', ['e', {'f': 'g'}]), + ('value__j', None), + ('value__k', {'l': 'm'}), + ('value__n', [None]), + ] + for lookup, expected in tests: + with self.subTest(lookup=lookup): + self.assertEqual(qs.values_list(lookup, flat=True).get(), expected) + @skipUnlessDBFeature('supports_json_field_contains') def test_key_contains(self): self.assertIs(NullableJSONModel.objects.filter(value__foo__contains='ar').exists(), False)