summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorSimon Charette <simon.charette@zapier.com>2019-09-15 23:25:50 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-16 08:55:16 +0200
commitdb181f4b7ceac2a7050d462224bf5109dcd4790d (patch)
tree2f9ec38c4edf2ef1a08dc04005b671a1e20b21e3 /tests/postgres_tests
parent0cdd27de1a679d0869bd0bc85ccfef0fc32bcf00 (diff)
[2.1.x] Fixed #30769 -- Fixed a crash when filtering against a subquery JSON/HStoreField annotation.
This was a regression introduced by 7deeabc7c7526786df6894429ce89a9c4b614086 to address CVE-2019-14234. Thanks Tim Kleinschmidt for the report and Mariusz for the tests. Backport of 6c3dfba89215fc56fc27ef61829a6fff88be4abb from master.
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_hstore.py8
-rw-r--r--tests/postgres_tests/test_json.py8
2 files changed, 14 insertions, 2 deletions
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
index 65f0b3616b..a1984c8e1b 100644
--- a/tests/postgres_tests/test_hstore.py
+++ b/tests/postgres_tests/test_hstore.py
@@ -2,7 +2,7 @@ import json
from django.core import checks, exceptions, serializers
from django.db import connection
-from django.db.models.expressions import RawSQL
+from django.db.models.expressions import OuterRef, RawSQL, Subquery
from django.forms import Form
from django.test.utils import (
CaptureQueriesContext, isolate_apps, modify_settings,
@@ -213,6 +213,12 @@ class TestQuerying(HStoreTestCase):
queries[0]['sql'],
)
+ def test_obj_subquery_lookup(self):
+ qs = HStoreModel.objects.annotate(
+ value=Subquery(HStoreModel.objects.filter(pk=OuterRef('pk')).values('field')),
+ ).filter(value__a='b')
+ self.assertSequenceEqual(qs, self.objs[:2])
+
@isolate_apps('postgres_tests')
class TestChecks(PostgreSQLTestCase):
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index 2938150af3..e893e1a75a 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -5,7 +5,7 @@ from decimal import Decimal
from django.core import checks, exceptions, serializers
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection
-from django.db.models import F, Q
+from django.db.models import F, OuterRef, Q, Subquery
from django.db.models.expressions import RawSQL
from django.db.models.functions import Cast
from django.forms import CharField, Form, widgets
@@ -256,6 +256,12 @@ class TestQuerying(PostgreSQLTestCase):
[self.objs[7], self.objs[8]]
)
+ def test_obj_subquery_lookup(self):
+ qs = JSONModel.objects.annotate(
+ value=Subquery(JSONModel.objects.filter(pk=OuterRef('pk')).values('field')),
+ ).filter(value__a='b')
+ self.assertSequenceEqual(qs, [self.objs[7], self.objs[8]])
+
def test_deep_lookup_objs(self):
self.assertSequenceEqual(
JSONModel.objects.filter(field__k__l='m'),