Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Upgrade the JSON lookup from django 2.2.4
NyanKiyoshi8617f56cf397
diff --git a/saleor/core/fields.py b/saleor/core/fields.pyindex 728234534c..9458c20aa1 100644--- a/saleor/core/fields.py+++ b/saleor/core/fields.py@@ -65,13 +65,10 @@ class FromKeyLookup(Transform):lhs, params = compiler.compile(previous)if len(key_transforms) > 1:- return (- "(%s %s %%s)" % (lhs, self.nested_operator),- [key_transforms] + params,- )-- lookup = "'%s'" % self.key_name- return "(%s %s %s)" % (lhs, self.operator, lookup), params+ operator, lookup = self.nested_operator, key_transforms+ else:+ operator, lookup = self.operator, self.key_name+ return "(%s %s %%s)" % (lhs, operator), [lookup] + paramsclass KeyTransformFactory:diff --git a/tests/test_core.py b/tests/test_core.pyindex 76bb1cbc80..3a777efea4 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -4,9 +4,11 @@ from unittest.mock import Mock, patchfrom urllib.parse import urljoinimport pytest+from django.db import connectionfrom django.shortcuts import reversefrom django.templatetags.static import staticfrom django.test import Client, RequestFactory, override_settings+from django.test.utils import CaptureQueriesContextfrom django.urls import translate_urlfrom measurement.measures import Weightfrom prices import Money@@ -30,7 +32,7 @@ from saleor.core.weight import WeightUnits, convert_weightfrom saleor.discount.models import Sale, Voucherfrom saleor.giftcard.models import GiftCardfrom saleor.order.models import Order-from saleor.product.models import ProductImage+from saleor.product.models import Product, ProductImagefrom saleor.shipping.models import ShippingZonetype_schema = {@@ -330,3 +332,28 @@ def test_csrf_middleware_is_enabled():def test_get_country_name_by_code():country_name = get_country_name_by_code("PL")assert country_name == "Poland"+++ "key, expected",+ (+ ("test", ".\"attributes\" -> 'test') = '\"a\"'"),+ (+ "'test'); select current_date;",+ (+ "\"product_product\".\"attributes\" -> '''test''); "+ "select current_date;') = '\"a\"'"+ ),+ ),+ ("15", ".\"attributes\" -> '15') = '\"a\"'"),+ ),+)+def test_filterable_json(key, expected):+ with CaptureQueriesContext(connection) as queries:+ Product.objects.only("pk").filter(+ **{f"attributes__from_key_{key}": "a"}+ ).first()++ queries = list(queries)+ assert len(queries) == 1+ assert expected in queries[0]["sql"]