Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Flatten metadata
fowczarekdc64a98b23b7
diff --git a/saleor/core/migrations/0001_migrate_metadata.py b/saleor/core/migrations/0001_migrate_metadata.pynew file mode 100644index 0000000000..6afa5fe3fb--- /dev/null+++ b/saleor/core/migrations/0001_migrate_metadata.py@@ -0,0 +1,126 @@+# Generated by Django 2.2.9 on 2020-02-07 07:32++from django.db import migrations+++def flatten_model_metadata(model_with_metadata):+ updated_fields = []+ public_meta = model_with_metadata.meta+ private_meta = model_with_metadata.private_meta+ if public_meta:+ model_with_metadata.meta = flatten_metadata(public_meta)+ updated_fields.append("meta")+ if private_meta:+ model_with_metadata.private_meta = flatten_metadata(private_meta)+ updated_fields.append("private_meta")+ if updated_fields:+ model_with_metadata.save(update_fields=updated_fields)+++def flatten_metadata(metadata):+ flattened_metadata = {}+ for _, namespace in metadata.items():+ for client_name, client in namespace.items():+ for key, value in client.items():+ flattened_key = client_name + "." + key+ if flattened_key in flattened_metadata:+ raise Exception(f"Meta key {flattened_key} is duplicated.")+ flattened_metadata[flattened_key] = value+ return flattened_metadata+++def flatten_attributes_metadata(apps, _schema_editor):+ Attribute = apps.get_model("product", "Attribute")+ for attribute in Attribute.objects.all():+ flatten_model_metadata(attribute)+++def flatten_categories_metadata(apps, _schema_editor):+ Category = apps.get_model("product", "Category")+ for category in Category.objects.all():+ flatten_model_metadata(category)+++def flatten_checkouts_metadata(apps, _schema_editor):+ Checkout = apps.get_model("checkout", "Checkout")+ for checkout in Checkout.objects.all():+ flatten_model_metadata(checkout)+++def flatten_collections_metadata(apps, _schema_editor):+ Collection = apps.get_model("product", "Collection")+ for collection in Collection.objects.all():+ flatten_model_metadata(collection)+++def flatten_digital_contents_metadata(apps, _schema_editor):+ DigitalContent = apps.get_model("product", "DigitalContent")+ for digital_content in DigitalContent.objects.all():+ flatten_model_metadata(digital_content)+++def flatten_fulfillments_metadata(apps, _schema_editor):+ Fulfillment = apps.get_model("order", "Fulfillment")+ for fulfillment in Fulfillment.objects.all():+ flatten_model_metadata(fulfillment)+++def flatten_orders_metadata(apps, _schema_editor):+ Order = apps.get_model("order", "Order")+ for order in Order.objects.all():+ flatten_model_metadata(order)+++def flatten_products_metadata(apps, _schema_editor):+ Product = apps.get_model("product", "Product")+ for product in Product.objects.all():+ flatten_model_metadata(product)+++def flatten_product_types_metadata(apps, _schema_editor):+ ProductType = apps.get_model("product", "ProductType")+ for product_type in ProductType.objects.all():+ flatten_model_metadata(product_type)+++def flatten_product_variants_metadata(apps, _schema_editor):+ ProductVariant = apps.get_model("product", "ProductVariant")+ for product_variant in ProductVariant.objects.all():+ flatten_model_metadata(product_variant)+++def flatten_service_accounts_metadata(apps, _schema_editor):+ ServiceAccount = apps.get_model("account", "ServiceAccount")+ for service_account in ServiceAccount.objects.all():+ flatten_model_metadata(service_account)+++def flatten_users_metadata(apps, _schema_editor):+ User = apps.get_model("account", "User")+ for user in User.objects.all():+ flatten_model_metadata(user)+++class Migration(migrations.Migration):++ dependencies = [+ ("account", "0038_auto_20200123_0034"),+ ("checkout", "0024_auto_20200120_0154"),+ ("order", "0077_auto_20191118_0606"),+ ("product", "0111_auto_20191209_0437"),+ ]++ operations = [+ migrations.RunPython(flatten_attributes_metadata),+ migrations.RunPython(flatten_categories_metadata),+ migrations.RunPython(flatten_checkouts_metadata),+ migrations.RunPython(flatten_collections_metadata),+ migrations.RunPython(flatten_digital_contents_metadata),+ migrations.RunPython(flatten_fulfillments_metadata),+ migrations.RunPython(flatten_orders_metadata),+ migrations.RunPython(flatten_products_metadata),+ migrations.RunPython(flatten_product_types_metadata),+ migrations.RunPython(flatten_product_variants_metadata),+ migrations.RunPython(flatten_service_accounts_metadata),+ migrations.RunPython(flatten_users_metadata),+ ]diff --git a/saleor/core/models.py b/saleor/core/models.pyindex 54d57aca32..b030fca7bf 100644--- a/saleor/core/models.py+++ b/saleor/core/models.py@@ -82,24 +82,32 @@ class ModelWithMetadata(models.Model):class Meta:abstract = True- def get_private_meta(self, namespace: str, client: str) -> dict:- return self.private_meta.get(namespace, {}).get(client, {})+ def get_private_meta(self, key: str):+ return self.private_meta.get(key, None)- def store_private_meta(self, namespace: str, client: str, item: dict):- if namespace not in self.private_meta:- self.private_meta[namespace] = {}- self.private_meta[namespace][str(client)] = item+ def store_private_meta(self, items: dict):+ if not self.private_meta:+ self.private_meta = {}+ self.private_meta.update(items)- def clear_stored_private_meta_for_client(self, namespace: str, client: str):- self.private_meta.get(namespace, {}).pop(client, None)+ def clear_private_meta(self):+ self.private_meta = {}- def get_meta(self, namespace: str, client: str) -> dict:- return self.meta.get(namespace, {}).get(client, {})+ def delete_private_meta(self, key: str):+ if key in self.private_meta:+ del self.private_meta[key]- def store_meta(self, namespace: str, client: str, item: dict):- if namespace not in self.meta:- self.meta[namespace] = {}- self.meta[namespace][str(client)] = item+ def get_meta(self, key: str):+ return self.meta.get(key, None)- def clear_stored_meta_for_client(self, namespace: str, client: str):- self.meta.get(namespace, {}).pop(client, None)+ def store_meta(self, items: dict):+ if not self.meta:+ self.meta = {}+ self.meta.update(items)++ def clear_meta(self):+ self.meta = {}++ def delete_meta(self, key: str):+ if key in self.meta:+ del self.meta[key]diff --git a/saleor/extensions/plugins/avatax/__init__.py b/saleor/extensions/plugins/avatax/__init__.pyindex 2013f86b7a..757d5bd832 100644--- a/saleor/extensions/plugins/avatax/__init__.py+++ b/saleor/extensions/plugins/avatax/__init__.py@@ -22,8 +22,8 @@ if TYPE_CHECKING:logger = logging.getLogger(__name__)-META_FIELD = "avatax"-META_NAMESPACE = "taxes"+META_CODE_KEY = "avatax.code"+META_DESCRIPTION_KEY = "avatax.description"CACHE_TIME = 60 * 60 # 1 hourTAX_CODES_CACHE_TIME = 60 * 60 * 24 * 7 # 7 daysCACHE_KEY = "avatax_request_id_"@@ -447,6 +447,6 @@ def get_cached_tax_codes_or_fetch(def retrieve_tax_code_from_meta(obj: Union["Product", "ProductVariant", "ProductType"]):- tax = obj.meta.get("taxes", {}).get(META_FIELD, {})+ tax_code = obj.get_meta(META_CODE_KEY)# O9999999 - "Temporary Unmapped Other SKU - taxable default"- return tax.get("code", "O9999999")+ return tax_code if tax_code else "O9999999"diff --git a/saleor/extensions/plugins/avatax/plugin.py b/saleor/extensions/plugins/avatax/plugin.pyindex 0912054820..94840f1f61 100644--- a/saleor/extensions/plugins/avatax/plugin.py+++ b/saleor/extensions/plugins/avatax/plugin.py@@ -12,8 +12,8 @@ from ... import ConfigurationTypeFieldfrom ...base_plugin import BasePluginfrom ...error_codes import ExtensionsErrorCodefrom . import (- META_FIELD,- META_NAMESPACE,+ META_CODE_KEY,+ META_DESCRIPTION_KEY,AvataxConfiguration,CustomerErrors,TransactionType,@@ -383,12 +383,8 @@ class AvataxPlugin(BasePlugin):returntax_description = codes[tax_code]- tax_item = {"code": tax_code, "description": tax_description}- stored_tax_meta = obj.get_meta(namespace=META_NAMESPACE, client=META_FIELD)- stored_tax_meta.update(tax_item)- obj.store_meta(- namespace=META_NAMESPACE, client=META_FIELD, item=stored_tax_meta- )+ tax_item = {META_CODE_KEY: tax_code, META_CODE_KEY: tax_description}+ obj.store_meta(items=tax_item)obj.save()def get_tax_code_from_object_meta(@@ -398,8 +394,12 @@ class AvataxPlugin(BasePlugin):if not self.active:return previous_value- tax = obj.get_meta(namespace=META_NAMESPACE, client=META_FIELD)- return TaxType(code=tax.get("code", ""), description=tax.get("description", ""))+ tax_code = obj.get_meta(META_CODE_KEY)+ tax_description = obj.get_meta(META_DESCRIPTION_KEY)+ return TaxType(+ code=tax_code if tax_code else "",+ description=tax_description if tax_description else "",+ )def show_taxes_on_storefront(self, previous_value: bool) -> bool:self._initialize_plugin_configuration()diff --git a/saleor/extensions/plugins/vatlayer/plugin.py b/saleor/extensions/plugins/vatlayer/plugin.pyindex a45baaa460..f45ccb952c 100644--- a/saleor/extensions/plugins/vatlayer/plugin.py+++ b/saleor/extensions/plugins/vatlayer/plugin.py@@ -31,8 +31,8 @@ if TYPE_CHECKING:class VatlayerPlugin(BasePlugin):PLUGIN_NAME = "Vatlayer"- META_FIELD = "vatlayer"- META_NAMESPACE = "taxes"+ META_CODE_KEY = "vatlayer.code"+ META_DESCRIPTION_KEY = "vatlayer.description"def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)@@ -253,14 +253,8 @@ class VatlayerPlugin(BasePlugin):if tax_code not in dict(TaxRateType.CHOICES):return previous_value- tax_item = {"code": tax_code, "description": tax_code}- stored_tax_meta = obj.get_meta(- namespace=self.META_NAMESPACE, client=self.META_FIELD- )- stored_tax_meta.update(tax_item)- obj.store_meta(- namespace=self.META_NAMESPACE, client=self.META_FIELD, item=stored_tax_meta- )+ tax_item = {self.META_CODE_KEY: tax_code, self.META_CODE_KEY: tax_code}+ obj.store_meta(items=tax_item)obj.save()return previous_value@@ -276,8 +270,12 @@ class VatlayerPlugin(BasePlugin):def __get_tax_code_from_object_meta(self, obj: Union["Product", "ProductType"]) -> "TaxType":- tax = obj.get_meta(namespace=self.META_NAMESPACE, client=self.META_FIELD)- return TaxType(code=tax.get("code", ""), description=tax.get("description", ""))+ tax_code = obj.get_meta(self.META_CODE_KEY)+ tax_description = obj.get_meta(self.META_DESCRIPTION_KEY)+ return TaxType(+ code=tax_code if tax_code else "",+ description=tax_description if tax_description else "",+ )def get_tax_rate_percentage_value(self, obj: Union["Product", "ProductType"], country: Country, previous_valuediff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.pyindex 5716926f52..7598c58bef 100644--- a/saleor/graphql/account/mutations/account.py+++ b/saleor/graphql/account/mutations/account.py@@ -13,7 +13,7 @@ from ...account.types import Address, AddressInput, Userfrom ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutationfrom ...core.types.common import AccountErrorfrom ...meta.deprecated.mutations import UpdateMetaBaseMutation-from ...meta.types import MetaInput+from ...meta.deprecated.types import MetaInputfrom .base import (INVALID_TOKEN,BaseAddressDelete,@@ -318,7 +318,11 @@ class AccountSetDefaultAddress(BaseMutation):class AccountUpdateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates metadata of the logged-in user."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Updates metadata of the logged-in user."+ )model = models.Userpublic = Trueerror_type_class = AccountErrordiff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.pyindex 5a0c5ed672..bd799d8623 100644--- a/saleor/graphql/account/mutations/base.py+++ b/saleor/graphql/account/mutations/base.py@@ -431,7 +431,11 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):class UserUpdateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates metadata for user."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Updates metadata for user."+ )model = models.Userpublic = Trueerror_type_class = AccountError@@ -441,7 +445,11 @@ class UserUpdateMeta(UpdateMetaBaseMutation):class UserClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clear metadata for user."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clear metadata for user."+ )model = models.Userpublic = Trueerror_type_class = AccountErrordiff --git a/saleor/graphql/account/mutations/service_account.py b/saleor/graphql/account/mutations/service_account.pyindex 3214d52ed4..84479a9249 100644--- a/saleor/graphql/account/mutations/service_account.py+++ b/saleor/graphql/account/mutations/service_account.py@@ -148,7 +148,11 @@ class ServiceAccountDelete(ModelDeleteMutation):class ServiceAccountUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates private metadata for a service account."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Updates private metadata for a service account."+ )permissions = (AccountPermissions.MANAGE_SERVICE_ACCOUNTS,)model = models.ServiceAccountpublic = False@@ -158,7 +162,11 @@ class ServiceAccountUpdatePrivateMeta(UpdateMetaBaseMutation):class ServiceAccountClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clear private metadata for a service account."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clear private metadata for a service account."+ )model = models.ServiceAccountpermissions = (AccountPermissions.MANAGE_SERVICE_ACCOUNTS,)public = Falsediff --git a/saleor/graphql/account/mutations/staff.py b/saleor/graphql/account/mutations/staff.pyindex 00f7209e69..22d15c7b93 100644--- a/saleor/graphql/account/mutations/staff.py+++ b/saleor/graphql/account/mutations/staff.py@@ -416,7 +416,11 @@ class UserAvatarDelete(BaseMutation):class UserUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates private metadata for user."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Updates private metadata for user."+ )permissions = (AccountPermissions.MANAGE_USERS,)model = models.Userpublic = False@@ -426,7 +430,11 @@ class UserUpdatePrivateMeta(UpdateMetaBaseMutation):class UserClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clear private metadata for user."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clear private metadata for user."+ )model = models.Userpermissions = (AccountPermissions.MANAGE_USERS,)public = Falsediff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex f93b9eb336..22d1e4a267 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -12,12 +12,11 @@ from ...order import models as order_modelsfrom ..checkout.types import Checkoutfrom ..core.connection import CountableDjangoObjectTypefrom ..core.fields import PrefetchingConnectionField-from ..core.resolvers import resolve_meta, resolve_private_metafrom ..core.types import CountryDisplay, Image, PermissionDisplayfrom ..core.utils import get_node_optimizedfrom ..decorators import one_of_permissions_required, permission_required+from ..meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ..meta.types import ObjectWithMetadata-from ..utils import format_permissions_for_displayfrom ..wishlist.resolvers import resolve_wishlist_items_from_userfrom ..wishlist.types import WishlistItem@@ -231,9 +230,14 @@ class ServiceAccount(CountableDjangoObjectType):return root.tokens.all()@staticmethod- def resolve_meta(root, info):+ def resolve_meta(root: models.ServiceAccount, info):return resolve_meta(root, info)+ @staticmethod+ @permission_required(AccountPermissions.MANAGE_SERVICE_ACCOUNTS)+ def resolve_private_meta(root: models.ServiceAccount, _info):+ return resolve_private_meta(root, _info)+@staticmethoddef __resolve_reference(root, _info, **_kwargs):return graphene.Node.get_node_from_global_id(_info, root.id)@@ -364,11 +368,11 @@ class User(CountableDjangoObjectType):@one_of_permissions_required([AccountPermissions.MANAGE_USERS, AccountPermissions.MANAGE_STAFF])- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.User, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.User, _info):return resolve_meta(root, _info)@staticmethoddiff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex d18004d2d8..f43398dccf 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -842,7 +842,11 @@ class CheckoutRemovePromoCode(BaseMutation):class CheckoutUpdateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates metadata for checkout."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Updates metadata for checkout."+ )permissions = (OrderPermissions.MANAGE_ORDERS,)model = models.Checkoutpublic = True@@ -852,7 +856,11 @@ class CheckoutUpdateMeta(UpdateMetaBaseMutation):class CheckoutUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates private metadata for checkout."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Updates private metadata for checkout."+ )permissions = (OrderPermissions.MANAGE_ORDERS,)model = models.Checkoutpublic = False@@ -862,7 +870,11 @@ class CheckoutUpdatePrivateMeta(UpdateMetaBaseMutation):class CheckoutClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clear metadata for checkout."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clear metadata for checkout."+ )permissions = (OrderPermissions.MANAGE_ORDERS,)model = models.Checkoutpublic = True@@ -872,7 +884,11 @@ class CheckoutClearMeta(ClearMetaBaseMutation):class CheckoutClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clear private metadata for checkout."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clear private metadata for checkout."+ )permissions = (OrderPermissions.MANAGE_ORDERS,)model = models.Checkoutpublic = Falsediff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex df04737fcf..1ec4c6de00 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -8,10 +8,10 @@ from ...core.permissions import AccountPermissions, CheckoutPermissionsfrom ...core.taxes import display_gross_prices, zero_taxed_moneyfrom ...extensions.manager import get_extensions_managerfrom ..core.connection import CountableDjangoObjectType-from ..core.resolvers import resolve_meta, resolve_private_metafrom ..core.types.money import TaxedMoneyfrom ..decorators import permission_requiredfrom ..giftcard.types import GiftCard+from ..meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ..meta.types import ObjectWithMetadatafrom ..shipping.types import ShippingMethoddiff --git a/saleor/graphql/core/resolvers.py b/saleor/graphql/core/resolvers.pydeleted file mode 100644index 878aa39dc3..0000000000--- a/saleor/graphql/core/resolvers.py+++ /dev/null@@ -1,21 +0,0 @@-from operator import itemgetter---def resolve_private_meta(root, _info):- return sorted(- [- {"namespace": namespace, "metadata": data}- for namespace, data in root.private_meta.items()- ],- key=itemgetter("namespace"),- )---def resolve_meta(root, _info):- return sorted(- [- {"namespace": namespace, "metadata": data}- for namespace, data in root.meta.items()- ],- key=itemgetter("namespace"),- )diff --git a/saleor/graphql/meta/deprecated/mutations.py b/saleor/graphql/meta/deprecated/mutations.pyindex 402952c982..9e39c18e6d 100644--- a/saleor/graphql/meta/deprecated/mutations.py+++ b/saleor/graphql/meta/deprecated/mutations.py@@ -1,9 +1,10 @@+# Deprecated we should remove it in #5221import graphenefrom django.core.exceptions import ImproperlyConfiguredfrom graphene_django.registry import get_global_registryfrom ...core.mutations import BaseMutation, get_model_name, get_output_fields-from ..types import MetaInput, MetaPath+from .types import MetaInput, MetaPathregistry = get_global_registry()@@ -69,6 +70,14 @@ class BaseMetadataMutation(BaseMutation):else getattr(instance, "clear_stored_private_meta_for_client"))+ @classmethod+ def get_delete_method(cls, instance):+ return (+ getattr(instance, "delete_meta")+ if cls._meta.public+ else getattr(instance, "delete_private_meta")+ )+@classmethoddef get_instance(cls, info, **data):object_id = data.get("id")@@ -99,15 +108,10 @@ class UpdateMetaBaseMutation(BaseMetadataMutation):@classmethoddef perform_mutation(cls, root, info, **data):instance = cls.get_instance(info, **data)- get_meta = cls.get_meta_method(instance)store_meta = cls.get_store_method(instance)metadata = data.pop("input")- stored_data = get_meta(metadata.namespace, metadata.client_name)- stored_data[metadata.key] = metadata.value- store_meta(- namespace=metadata.namespace, client=metadata.client_name, item=stored_data- )+ store_meta(items={metadata.key: metadata.value})instance.save()return cls.success_response(instance)@@ -126,22 +130,11 @@ class ClearMetaBaseMutation(BaseMetadataMutation):@classmethoddef perform_mutation(cls, root, info, **data):instance = cls.get_instance(info, **data)- get_meta = cls.get_meta_method(instance)- store_meta = cls.get_store_method(instance)- clear_meta = cls.get_clear_method(instance)+ delete_meta = cls.get_delete_method(instance)metadata = data.pop("input")- stored_data = get_meta(metadata.namespace, metadata.client_name)-- cleared_value = stored_data.pop(metadata.key, None)- if not stored_data:- clear_meta(metadata.namespace, metadata.client_name)- instance.save()- elif cleared_value is not None:- store_meta(- namespace=metadata.namespace,- client=metadata.client_name,- item=stored_data,- )- instance.save()++ delete_meta(metadata.key)+ instance.save()+return cls.success_response(instance)diff --git a/saleor/graphql/meta/deprecated/resolvers.py b/saleor/graphql/meta/deprecated/resolvers.pynew file mode 100644index 0000000000..5b50bfe017--- /dev/null+++ b/saleor/graphql/meta/deprecated/resolvers.py@@ -0,0 +1,7 @@+# Deprecated we should remove it in #5221+def resolve_private_meta(root, _info):+ return [root.private_meta]+++def resolve_meta(root, _info):+ return [root.meta]diff --git a/saleor/graphql/meta/deprecated/types.py b/saleor/graphql/meta/deprecated/types.pynew file mode 100644index 0000000000..f7ee1cd77b--- /dev/null+++ b/saleor/graphql/meta/deprecated/types.py@@ -0,0 +1,53 @@+# Deprecated we should remove it in #5221+import graphene++from ..resolvers import resolve_metadata+from ..types import MetaItem+++class MetaPath(graphene.InputObjectType):+ namespace = graphene.String(+ required=True, description="Name of metadata client group.",+ )+ client_name = graphene.String(required=True, description="Metadata client's name.",)+ key = graphene.String(required=True, description="Key for stored data.")+++class MetaInput(MetaPath):+ value = graphene.String(required=True, description="Stored metadata value.")+++class MetaClientStore(graphene.ObjectType):+ name = graphene.String(required=True, description="Metadata client's name.")+ metadata = graphene.List(+ MetaItem, required=True, description="Metadata stored for a client."+ )++ @staticmethod+ def resolve_metadata(root, _info):+ return resolve_metadata(root)++ @staticmethod+ def resolve_name(_root, _info):+ return ""+++class MetaStore(graphene.ObjectType):+ namespace = graphene.String(+ required=True, description="Name of metadata client group."+ )+ clients = graphene.List(+ MetaClientStore,+ required=True,+ description="List of clients that stored metadata in a group.",+ )++ @staticmethod+ def resolve_clients(root: dict, _info):+ if root:+ return [root]+ return []++ @staticmethod+ def resolve_namespace(_root, _info):+ return ""diff --git a/saleor/graphql/meta/mutations.py b/saleor/graphql/meta/mutations.pyindex 9ce05f7b18..ef95d38bbe 100644--- a/saleor/graphql/meta/mutations.py+++ b/saleor/graphql/meta/mutations.py@@ -2,57 +2,12 @@ import graphenefrom django.core.exceptions import ValidationErrorfrom graphql_jwt.exceptions import PermissionDenied-from ...account import models as account_modelsfrom ...core import modelsfrom ...core.error_codes import MetaErrorCode-from ...core.permissions import AccountPermissions, OrderPermissions, ProductPermissionsfrom ..core.mutations import BaseMutationfrom ..core.types.common import MetaError-from .types import MetaInput, MetaPath, ObjectWithMetadata---def no_permissions(_info, _object_pk):- return []---def public_user_permissions(info, user_pk):- user = account_models.User.objects.filter(pk=user_pk).first()- if not user:- raise PermissionDenied()- if info.context.user.pk == user.pk:- return []- if user.is_staff:- return [AccountPermissions.MANAGE_STAFF]- else:- return [AccountPermissions.MANAGE_USERS]---def product_permissions(_info, _object_pk):- return [ProductPermissions.MANAGE_PRODUCTS]---def order_permissions(_info, _object_pk):- return [OrderPermissions.MANAGE_ORDERS]---def service_account_permissions(_info, _object_pk):- return [AccountPermissions.MANAGE_SERVICE_ACCOUNTS]---PUBLIC_META_PERMISSION_MAP = {- "Attribute": product_permissions,- "Category": product_permissions,- "Checkout": no_permissions,- "Collection": product_permissions,- "DigitalContent": product_permissions,- "Fulfillment": order_permissions,- "Order": no_permissions,- "Product": product_permissions,- "ProductType": product_permissions,- "ProductVariant": product_permissions,- "ServiceAccount": service_account_permissions,- "User": public_user_permissions,-}+from .permissions import PUBLIC_META_PERMISSION_MAP+from .types import ObjectWithMetadataclass MetaPermissionOptions(graphene.types.mutation.MutationOptions):@@ -131,6 +86,11 @@ class BaseMetadataMutation(BaseMutation):return cls(**{"item": instance, "errors": []})+class MetaItemInput(graphene.InputObjectType):+ key = graphene.String(required=True, description="Key for stored data.")+ value = graphene.String(required=True, description="Stored metadata value.")++class UpdateMeta(BaseMetadataMutation):class Meta:description = "Updates metadata for item."@@ -140,7 +100,7 @@ class UpdateMeta(BaseMetadataMutation):class Arguments:id = graphene.ID(description="ID of an object to update.", required=True)- input = MetaInput(+ input = MetaItemInput(description="Fields required to update new or stored metadata item.",required=True,)@@ -150,50 +110,28 @@ class UpdateMeta(BaseMetadataMutation):instance = cls.get_instance(info, **data)if instance:metadata = data.pop("input")- stored_data = instance.get_meta(metadata.namespace, metadata.client_name)- stored_data[metadata.key] = metadata.value- instance.store_meta(- namespace=metadata.namespace,- client=metadata.client_name,- item=stored_data,- )+ item = {metadata.key: metadata.value}+ instance.store_meta(items=item)instance.save()return cls.success_response(instance)-class ClearMeta(BaseMetadataMutation):+class DeleteMeta(BaseMetadataMutation):class Meta:- description = "Clear metadata for item."+ description = "Delete metadata for key."permission_map = PUBLIC_META_PERMISSION_MAPerror_type_class = MetaErrorerror_type_field = "meta_errors"class Arguments:id = graphene.ID(description="ID of an object to update.", required=True)- input = MetaPath(- description="Fields required to identify stored metadata item.",- required=True,- )+ key = graphene.String(description="Key for value to delete.", required=True)@classmethoddef perform_mutation(cls, root, info, **data):instance = cls.get_instance(info, **data)if instance:- metadata = data.pop("input")- # TODO: We should refactore clearing meta- # Don't forget about test test_clear_public_metadata_remove_empty_namespace- stored_data = instance.get_meta(metadata.namespace, metadata.client_name)- cleared_value = stored_data.pop(metadata.key, None)- if not stored_data:- instance.clear_stored_meta_for_client(- metadata.namespace, metadata.client_name- )- instance.save()- elif cleared_value is not None:- instance.store_meta(- namespace=metadata.namespace,- client=metadata.client_name,- item=stored_data,- )- instance.save()+ metadata_key = data.pop("key")+ instance.delete_meta(metadata_key)+ instance.save()return cls.success_response(instance)diff --git a/saleor/graphql/meta/permissions.py b/saleor/graphql/meta/permissions.pynew file mode 100644index 0000000000..772ee738dc--- /dev/null+++ b/saleor/graphql/meta/permissions.py@@ -0,0 +1,84 @@+from typing import Any, List++from graphql_jwt.exceptions import PermissionDenied++from ...account import models as account_models+from ...core.permissions import (+ AccountPermissions,+ BasePermissionEnum,+ CheckoutPermissions,+ OrderPermissions,+ ProductPermissions,+)+++def no_permissions(_info, _object_pk: Any) -> List[BasePermissionEnum]:+ return []+++def public_user_permissions(info, user_pk: int) -> List[BasePermissionEnum]:+ user = account_models.User.objects.filter(pk=user_pk).first()+ if not user:+ raise PermissionDenied()+ if info.context.user.pk == user.pk:+ return []+ if user.is_staff:+ return [AccountPermissions.MANAGE_STAFF]+ return [AccountPermissions.MANAGE_USERS]+++def private_user_permissions(_info, user_pk: int) -> List[BasePermissionEnum]:+ user = account_models.User.objects.filter(pk=user_pk).first()+ if not user:+ raise PermissionDenied()+ if user.is_staff:+ return [AccountPermissions.MANAGE_STAFF]+ return [AccountPermissions.MANAGE_USERS]+++def product_permissions(_info, _object_pk: Any) -> List[BasePermissionEnum]:+ return [ProductPermissions.MANAGE_PRODUCTS]+++def order_permissions(_info, _object_pk: Any) -> List[BasePermissionEnum]:+ return [OrderPermissions.MANAGE_ORDERS]+++def service_account_permissions(_info, _object_pk: int) -> List[BasePermissionEnum]:+ return [AccountPermissions.MANAGE_SERVICE_ACCOUNTS]+++def checkout_permissions(_info, _object_pk: Any) -> List[BasePermissionEnum]:+ return [CheckoutPermissions.MANAGE_CHECKOUTS]+++PUBLIC_META_PERMISSION_MAP = {+ "Attribute": product_permissions,+ "Category": product_permissions,+ "Checkout": no_permissions,+ "Collection": product_permissions,+ "DigitalContent": product_permissions,+ "Fulfillment": order_permissions,+ "Order": no_permissions,+ "Product": product_permissions,+ "ProductType": product_permissions,+ "ProductVariant": product_permissions,+ "ServiceAccount": service_account_permissions,+ "User": public_user_permissions,+}+++PRIVATE_META_PERMISSION_MAP = {+ "Attribute": product_permissions,+ "Category": product_permissions,+ "Checkout": checkout_permissions,+ "Collection": product_permissions,+ "DigitalContent": product_permissions,+ "Fulfillment": order_permissions,+ "Order": order_permissions,+ "Product": product_permissions,+ "ProductType": product_permissions,+ "ProductVariant": product_permissions,+ "ServiceAccount": service_account_permissions,+ "User": private_user_permissions,+}diff --git a/saleor/graphql/meta/resolvers.py b/saleor/graphql/meta/resolvers.pynew file mode 100644index 0000000000..fa04fbaac7--- /dev/null+++ b/saleor/graphql/meta/resolvers.py@@ -0,0 +1,71 @@+from operator import itemgetter++from graphql_jwt.exceptions import PermissionDenied++from ...account import models as account_models+from ...checkout import models as checkout_models+from ...core.models import ModelWithMetadata+from ...order import models as order_models+from ...product import models as product_models+from ..utils import get_user_or_service_account_from_context+from .permissions import PRIVATE_META_PERMISSION_MAP+++def resolve_object_with_metadata_type(instance: ModelWithMetadata):+ # Imports inside resolvers to avoid circular imports.+ from ..account import types as account_types+ from ..checkout import types as checkout_types+ from ..order import types as order_types+ from ..product import types as product_types++ if isinstance(instance, product_models.Attribute):+ return product_types.Attribute+ if isinstance(instance, product_models.Category):+ return product_types.Category+ if isinstance(instance, checkout_models.Checkout):+ return checkout_types.Checkout+ if isinstance(instance, product_models.Collection):+ return product_types.Collection+ if isinstance(instance, product_models.DigitalContent):+ return product_types.DigitalContent+ if isinstance(instance, order_models.Fulfillment):+ return order_types.Fulfillment+ if isinstance(instance, order_models.Order):+ return order_types.Order+ if isinstance(instance, product_models.Product):+ return product_types.Product+ if isinstance(instance, product_models.ProductType):+ return product_types.ProductType+ if isinstance(instance, product_models.ProductVariant):+ return product_types.ProductVariant+ if isinstance(instance, account_models.ServiceAccount):+ return account_types.ServiceAccount+ if isinstance(instance, account_models.User):+ return account_types.User+ return None+++def resolve_metadata(metadata: dict):+ return sorted(+ [{"key": k, "value": v} for k, v in metadata.items()], key=itemgetter("key"),+ )+++def resolve_private_metadata(root: ModelWithMetadata, info):+ item_type = resolve_object_with_metadata_type(root)+ if not item_type:+ raise PermissionDenied()++ get_required_permission = PRIVATE_META_PERMISSION_MAP[item_type.__name__]+ if not get_required_permission:+ raise PermissionDenied()++ required_permission = get_required_permission(info, root.pk)+ if not required_permission:+ raise PermissionDenied()++ requester = get_user_or_service_account_from_context(info.context)+ if not requester.has_perms(required_permission):+ raise PermissionDenied()++ return resolve_metadata(root.private_meta)diff --git a/saleor/graphql/meta/schema.py b/saleor/graphql/meta/schema.pyindex ec44932492..3a6f05c449 100644--- a/saleor/graphql/meta/schema.py+++ b/saleor/graphql/meta/schema.py@@ -1,8 +1,8 @@import graphene-from .mutations import ClearMeta, UpdateMeta+from .mutations import DeleteMeta, UpdateMetaclass MetaMutations(graphene.ObjectType):- clear_meta = ClearMeta.Field()+ delete_meta = DeleteMeta.Field()update_meta = UpdateMeta.Field()diff --git a/saleor/graphql/meta/types.py b/saleor/graphql/meta/types.pyindex 3f44c55e00..70f6683032 100644--- a/saleor/graphql/meta/types.py+++ b/saleor/graphql/meta/types.py@@ -1,23 +1,11 @@-from operator import itemgetter-import graphene-from ...account import models as account_models-from ...checkout import models as checkout_models-from ...order import models as order_models-from ...product import models as product_models---class MetaPath(graphene.InputObjectType):- namespace = graphene.String(- required=True, description="Name of metadata client group."- )- client_name = graphene.String(required=True, description="Metadata client's name.")- key = graphene.String(required=True, description="Key for stored data.")---class MetaInput(MetaPath):- value = graphene.String(required=True, description="Stored metadata value.")+from ...core.models import ModelWithMetadata+from .resolvers import (+ resolve_metadata,+ resolve_object_with_metadata_type,+ resolve_private_metadata,+)class MetaItem(graphene.ObjectType):@@ -25,83 +13,43 @@ class MetaItem(graphene.ObjectType):value = graphene.String(required=True, description="Stored metadata value.")-class MetaClientStore(graphene.ObjectType):- name = graphene.String(required=True, description="Metadata client's name.")- metadata = graphene.List(- MetaItem, required=True, description="Metadata stored for a client."- )-- @staticmethod- def resolve_metadata(root, _info):- return sorted(- [{"key": k, "value": v} for k, v in root["metadata"].items()],- key=itemgetter("key"),- )---class MetaStore(graphene.ObjectType):- namespace = graphene.String(- required=True, description="Name of metadata client group."+class ObjectWithMetadata(graphene.Interface):+ private_metadata = graphene.List(+ MetaItem,+ required=True,+ description="List of publicly stored metadata namespaces.",)- clients = graphene.List(- MetaClientStore,+ metadata = graphene.List(+ MetaItem,required=True,- description="List of clients that stored metadata in a group.",+ description="List of publicly stored metadata namespaces.",)- @staticmethod- def resolve_clients(root: dict, _info):- return sorted(- [- {"name": key, "metadata": value}- for key, value in root["metadata"].items()- ],- key=itemgetter("name"),- )-+ # Deprecated we should remove it in #5221-class ObjectWithMetadata(graphene.Interface):private_meta = graphene.List(- MetaStore,+ "saleor.graphql.meta.deprecated.types.MetaStore",required=True,description="List of privately stored metadata namespaces.",+ deprecation_reason="DEPRECATED: Will be removed in Saleor 2.11. "+ "use the `privetaMetadata` field instead. ",)meta = graphene.List(- MetaStore,+ "saleor.graphql.meta.deprecated.types.MetaStore",required=True,description="List of publicly stored metadata namespaces.",+ deprecation_reason="DEPRECATED: Will be removed in Saleor 2.11. "+ "use the `privetaMetadata` field instead. ",)- @classmethod- def resolve_type(cls, instance, info):- # Imports inside resolvers to avoid circular imports.- from ..account import types as account_types- from ..checkout import types as checkout_types- from ..order import types as order_types- from ..product import types as product_types+ @staticmethod+ def resolve_metadata(root: ModelWithMetadata, _info):+ return resolve_metadata(root.meta)- if isinstance(instance, product_models.Attribute):- return product_types.Attribute- if isinstance(instance, product_models.Category):- return product_types.Category- if isinstance(instance, checkout_models.Checkout):- return checkout_types.Checkout- if isinstance(instance, product_models.Collection):- return product_types.Collection- if isinstance(instance, product_models.DigitalContent):- return product_types.DigitalContent- if isinstance(instance, order_models.Fulfillment):- return order_types.Fulfillment- if isinstance(instance, order_models.Order):- return order_types.Order- if isinstance(instance, product_models.Product):- return product_types.Product- if isinstance(instance, product_models.ProductType):- return product_types.ProductType- if isinstance(instance, product_models.ProductVariant):- return product_types.ProductVariant- if isinstance(instance, account_models.ServiceAccount):- return account_types.ServiceAccount- if isinstance(instance, account_models.User):- return account_types.User- return None+ @staticmethod+ def resolve_private_metadata(root: ModelWithMetadata, info):+ return resolve_private_metadata(root, info)++ @classmethod+ def resolve_type(cls, instance: ModelWithMetadata, _info):+ return resolve_object_with_metadata_type(instance)diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex b3ace67083..fe25e9bdd1 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -50,7 +50,11 @@ class FulfillmentCancelInput(graphene.InputObjectType):class FulfillmentClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clears metadata for fulfillment."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears metadata for fulfillment."+ )model = models.Fulfillmentpermissions = (OrderPermissions.MANAGE_ORDERS,)public = True@@ -58,7 +62,11 @@ class FulfillmentClearMeta(ClearMetaBaseMutation):class FulfillmentUpdateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates metadata for fulfillment."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Updates metadata for fulfillment."+ )model = models.Fulfillmentpermissions = (OrderPermissions.MANAGE_ORDERS,)public = True@@ -66,7 +74,11 @@ class FulfillmentUpdateMeta(UpdateMetaBaseMutation):class FulfillmentClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clears private metadata for fulfillment."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata for fulfillment."+ )model = models.Fulfillmentpermissions = (OrderPermissions.MANAGE_ORDERS,)public = False@@ -74,7 +86,11 @@ class FulfillmentClearPrivateMeta(ClearMetaBaseMutation):class FulfillmentUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates metadata for fulfillment."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Updates metadata for fulfillment."+ )model = models.Fulfillmentpermissions = (OrderPermissions.MANAGE_ORDERS,)public = Falsediff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex a0d578225b..ecf1c28ade 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -22,7 +22,7 @@ from ...core.mutations import BaseMutationfrom ...core.scalars import Decimalfrom ...core.types.common import OrderErrorfrom ...meta.deprecated.mutations import ClearMetaBaseMutation, UpdateMetaBaseMutation-from ...meta.types import MetaInput, MetaPath+from ...meta.deprecated.types import MetaInput, MetaPathfrom ...order.mutations.draft_orders import DraftOrderUpdatefrom ...order.types import Order, OrderEventfrom ...shipping.types import ShippingMethod@@ -442,7 +442,11 @@ class OrderRefund(BaseMutation):class OrderUpdateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates meta for order."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Updates meta for order."+ )model = models.Orderpublic = True@@ -463,7 +467,11 @@ class OrderUpdateMeta(UpdateMetaBaseMutation):class OrderUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Updates private meta for order."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Updates private meta for order."+ )model = models.Orderpermissions = (OrderPermissions.MANAGE_ORDERS,)public = False@@ -471,7 +479,11 @@ class OrderUpdatePrivateMeta(UpdateMetaBaseMutation):class OrderClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clears stored metadata value."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears stored metadata value."+ )model = models.Orderpermissions = (OrderPermissions.MANAGE_ORDERS,)public = True@@ -491,7 +503,11 @@ class OrderClearMeta(ClearMetaBaseMutation):class OrderClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clears stored private metadata value."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears stored private metadata value."+ )model = models.Orderpermissions = (OrderPermissions.MANAGE_ORDERS,)public = Falsediff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 0c46ae6f24..47323ab71a 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -13,11 +13,11 @@ from ...order.utils import get_valid_shipping_methods_for_orderfrom ...product.templatetags.product_images import get_product_image_thumbnailfrom ..account.types import Userfrom ..core.connection import CountableDjangoObjectType-from ..core.resolvers import resolve_meta, resolve_private_metafrom ..core.types.common import Imagefrom ..core.types.money import Money, TaxedMoneyfrom ..decorators import permission_requiredfrom ..giftcard.types import GiftCard+from ..meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ..meta.types import ObjectWithMetadatafrom ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..product.types import ProductVariantdiff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex 9b5ff1dd63..35c3946f4f 100644--- a/saleor/graphql/product/mutations/attributes.py+++ b/saleor/graphql/product/mutations/attributes.py@@ -497,7 +497,11 @@ class AttributeDelete(ModelDeleteMutation):class AttributeUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.Attribute- description = "Update public metadata for attribute."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for attribute."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -506,7 +510,11 @@ class AttributeUpdateMeta(UpdateMetaBaseMutation):class AttributeClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clears public metadata item for attribute."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata item for attribute."+ )model = models.Attributepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = True@@ -516,7 +524,11 @@ class AttributeClearMeta(ClearMetaBaseMutation):class AttributeUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Update public metadata for attribute."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update public metadata for attribute."+ )model = models.Attributepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = False@@ -526,7 +538,11 @@ class AttributeUpdatePrivateMeta(UpdateMetaBaseMutation):class AttributeClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clears public metadata item for attribute."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears public metadata item for attribute."+ )model = models.Attributepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falsediff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 7637a857b0..9c085864fb 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -399,7 +399,11 @@ class CollectionRemoveProducts(BaseMutation):class CollectionUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.Collection- description = "Update public metadata for collection."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for collection."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -409,7 +413,11 @@ class CollectionUpdateMeta(UpdateMetaBaseMutation):class CollectionClearMeta(ClearMetaBaseMutation):class Meta:model = models.Collection- description = "Clears public metadata for collection."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata for collection."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -419,7 +427,11 @@ class CollectionClearMeta(ClearMetaBaseMutation):class CollectionUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:model = models.Collection- description = "Update private metadata for collection."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update private metadata for collection."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -429,7 +441,11 @@ class CollectionUpdatePrivateMeta(UpdateMetaBaseMutation):class CollectionClearPrivateMeta(ClearMetaBaseMutation):class Meta:model = models.Collection- description = "Clears private metadata item for collection."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata item for collection."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -439,7 +455,11 @@ class CollectionClearPrivateMeta(ClearMetaBaseMutation):class CategoryUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.Category- description = "Update public metadata for category."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for category."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -449,7 +469,11 @@ class CategoryUpdateMeta(UpdateMetaBaseMutation):class CategoryClearMeta(ClearMetaBaseMutation):class Meta:model = models.Category- description = "Clears public metadata for category."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata for category."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -459,7 +483,11 @@ class CategoryClearMeta(ClearMetaBaseMutation):class CategoryUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:model = models.Category- description = "Update private metadata for category."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update private metadata for category."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -469,7 +497,11 @@ class CategoryUpdatePrivateMeta(UpdateMetaBaseMutation):class CategoryClearPrivateMeta(ClearMetaBaseMutation):class Meta:model = models.Category- description = "Clears private metadata for category."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata for category."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -998,7 +1030,11 @@ class ProductDelete(ModelDeleteMutation):class ProductUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.Product- description = "Update public metadata for product."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for product."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -1007,7 +1043,11 @@ class ProductUpdateMeta(UpdateMetaBaseMutation):class ProductClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clears public metadata item for product."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata item for product."+ )model = models.Productpermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = True@@ -1017,7 +1057,11 @@ class ProductClearMeta(ClearMetaBaseMutation):class ProductUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Update private metadata for product."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update private metadata for product."+ )model = models.Productpermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = False@@ -1027,7 +1071,11 @@ class ProductUpdatePrivateMeta(UpdateMetaBaseMutation):class ProductClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clears private metadata item for product."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata item for product."+ )model = models.Productpermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = False@@ -1246,7 +1294,11 @@ class ProductVariantDelete(ModelDeleteMutation):class ProductVariantUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.ProductVariant- description = "Update public metadata for product variant."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for product variant."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -1256,7 +1308,11 @@ class ProductVariantUpdateMeta(UpdateMetaBaseMutation):class ProductVariantClearMeta(ClearMetaBaseMutation):class Meta:model = models.ProductVariant- description = "Clears public metadata for product variant."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata for product variant."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -1266,7 +1322,11 @@ class ProductVariantClearMeta(ClearMetaBaseMutation):class ProductVariantUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:model = models.ProductVariant- description = "Update private metadata for product variant."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update private metadata for product variant."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -1276,7 +1336,11 @@ class ProductVariantUpdatePrivateMeta(UpdateMetaBaseMutation):class ProductVariantClearPrivateMeta(ClearMetaBaseMutation):class Meta:model = models.ProductVariant- description = "Clears private metadata for product variant."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata for product variant."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falseerror_type_class = ProductError@@ -1405,7 +1469,11 @@ class ProductTypeDelete(ModelDeleteMutation):class ProductTypeUpdateMeta(UpdateMetaBaseMutation):class Meta:model = models.ProductType- description = "Update public metadata for product type."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdateMeta` mutation instead."+ "Update public metadata for product type."+ )permissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Trueerror_type_class = ProductError@@ -1414,7 +1482,11 @@ class ProductTypeUpdateMeta(UpdateMetaBaseMutation):class ProductTypeClearMeta(ClearMetaBaseMutation):class Meta:- description = "Clears public metadata for product type."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeleteMeta` mutation instead."+ "Clears public metadata for product type."+ )model = models.ProductTypepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = True@@ -1424,7 +1496,11 @@ class ProductTypeClearMeta(ClearMetaBaseMutation):class ProductTypeUpdatePrivateMeta(UpdateMetaBaseMutation):class Meta:- description = "Update private metadata for product type."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `UpdatePrivateMeta` mutation instead."+ "Update private metadata for product type."+ )model = models.ProductTypepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = False@@ -1434,7 +1510,11 @@ class ProductTypeUpdatePrivateMeta(UpdateMetaBaseMutation):class ProductTypeClearPrivateMeta(ClearMetaBaseMutation):class Meta:- description = "Clears private metadata for product type."+ description = (+ "DEPRECATED: Will be removed in Saleor 2.11."+ "Use the `DeletePrivateMeta` mutation instead."+ "Clears private metadata for product type."+ )model = models.ProductTypepermissions = (ProductPermissions.MANAGE_PRODUCTS,)public = Falsediff --git a/saleor/graphql/product/types/attributes.py b/saleor/graphql/product/types/attributes.pyindex 18918bd872..c595d28766 100644--- a/saleor/graphql/product/types/attributes.py+++ b/saleor/graphql/product/types/attributes.py@@ -7,8 +7,8 @@ from graphene import relayfrom ....core.permissions import ProductPermissionsfrom ....product import modelsfrom ...core.connection import CountableDjangoObjectType-from ...core.resolvers import resolve_meta, resolve_private_metafrom ...decorators import permission_required+from ...meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ...meta.types import ObjectWithMetadatafrom ...translations.fields import TranslationFieldfrom ...translations.types import AttributeTranslation, AttributeValueTranslation@@ -106,11 +106,11 @@ class Attribute(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.Attribute, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.Attribute, _info):return resolve_meta(root, _info)@staticmethoddiff --git a/saleor/graphql/product/types/digital_contents.py b/saleor/graphql/product/types/digital_contents.pyindex 19d061b984..1c0dbb70f9 100644--- a/saleor/graphql/product/types/digital_contents.py+++ b/saleor/graphql/product/types/digital_contents.py@@ -5,8 +5,8 @@ from graphene import relayfrom ....core.permissions import ProductPermissionsfrom ....product import modelsfrom ...core.connection import CountableDjangoObjectType-from ...core.resolvers import resolve_meta, resolve_private_metafrom ...decorators import permission_required+from ...meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ...meta.types import ObjectWithMetadata@@ -52,9 +52,9 @@ class DigitalContent(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.DigitalContent, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.DigitalContent, _info):return resolve_meta(root, _info)diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex d38bcdb099..2fa550c0ef 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -31,9 +31,9 @@ from ....warehouse.availability import (from ...core.connection import CountableDjangoObjectTypefrom ...core.enums import ReportingPeriod, TaxRateTypefrom ...core.fields import FilterInputConnectionField, PrefetchingConnectionField-from ...core.resolvers import resolve_meta, resolve_private_metafrom ...core.types import Image, Money, MoneyRange, TaxedMoney, TaxedMoneyRange, TaxTypefrom ...decorators import permission_required+from ...meta.deprecated.resolvers import resolve_meta, resolve_private_metafrom ...meta.types import ObjectWithMetadatafrom ...translations.fields import TranslationFieldfrom ...translations.types import (@@ -362,6 +362,7 @@ class ProductVariant(CountableDjangoObjectType):# `resolve_report_product_sales` resolver.return getattr(root, "quantity_ordered", None)+ @staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)def resolve_quantity_allocated(root: models.ProductVariant, info):country = info.context.country@@ -388,11 +389,11 @@ class ProductVariant(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.ProductVariant, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.ProductVariant, _info):return resolve_meta(root, _info)@staticmethod@@ -594,11 +595,11 @@ class Product(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.Product, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.Product, _info):return resolve_meta(root, _info)@staticmethod@@ -688,11 +689,11 @@ class ProductType(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.ProductType, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.ProductType, _info):return resolve_meta(root, _info)@staticmethod@@ -757,11 +758,11 @@ class Collection(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.Collection, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.Collection, _info):return resolve_meta(root, _info)@staticmethod@@ -852,11 +853,11 @@ class Category(CountableDjangoObjectType):@staticmethod@permission_required(ProductPermissions.MANAGE_PRODUCTS)- def resolve_private_meta(root, _info):+ def resolve_private_meta(root: models.Category, _info):return resolve_private_meta(root, _info)@staticmethod- def resolve_meta(root, _info):+ def resolve_meta(root: models.Category, _info):return resolve_meta(root, _info)@staticmethoddiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex f2a4478723..476ba593c0 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -194,8 +194,10 @@ type Attribute implements Node, ObjectWithMetadata {id: ID!productTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!productVariantTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")inputType: AttributeInputTypeEnumname: Stringslug: String@@ -507,8 +509,10 @@ type Category implements Node, ObjectWithMetadata {slug: String!parent: Categorylevel: Int!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")ancestors(before: String, after: String, first: Int, last: Int): CategoryCountableConnectionproducts(before: String, after: String, first: Int, last: Int): ProductCountableConnectionurl: String@@ -644,8 +648,10 @@ type Checkout implements Node, ObjectWithMetadata {voucherCode: StringgiftCards: [GiftCard]id: ID!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")availableShippingMethods: [ShippingMethod]!availablePaymentGateways: [PaymentGateway]!email: String!@@ -841,12 +847,6 @@ type ChoiceValue {verbose: String}-type ClearMeta {- errors: [Error!]- metaErrors: [MetaError!]- item: ObjectWithMetadata-}-type Collection implements Node, ObjectWithMetadata {seoTitle: StringseoDescription: String@@ -857,8 +857,10 @@ type Collection implements Node, ObjectWithMetadata {publicationDate: DateisPublished: Boolean!slug: String!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")products(before: String, after: String, first: Int, last: Int): ProductCountableConnectionbackgroundImage(size: Int): Imagetranslation(languageCode: LanguageCodeEnum!): CollectionTranslation@@ -1408,6 +1410,12 @@ input DateTimeRangeInput {scalar Decimal+type DeleteMeta {+ errors: [Error!]+ metaErrors: [MetaError!]+ item: ObjectWithMetadata+}+type DigitalContent implements Node, ObjectWithMetadata {useDefaultSettings: Boolean!automaticFulfillment: Boolean!@@ -1417,8 +1425,10 @@ type DigitalContent implements Node, ObjectWithMetadata {urlValidDays: Inturls: [DigitalContentUrl]id: ID!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")}type DigitalContentCountableConnection {@@ -1609,8 +1619,10 @@ type Fulfillment implements Node, ObjectWithMetadata {status: FulfillmentStatus!trackingNumber: String!created: DateTime!- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")lines: [FulfillmentLine]statusDisplay: String}@@ -2090,6 +2102,11 @@ type MetaItem {value: String!}+input MetaItemInput {+ key: String!+ value: String!+}+input MetaPath {namespace: String!clientName: String!@@ -2272,8 +2289,8 @@ type Mutation {orderUpdateShipping(order: ID!, input: OrderUpdateShippingInput): OrderUpdateShippingorderVoid(id: ID!): OrderVoidorderBulkCancel(ids: [ID]!, restock: Boolean!): OrderBulkCancel- clearMeta(id: ID!, input: MetaPath!): ClearMeta- updateMeta(id: ID!, input: MetaInput!): UpdateMeta+ deleteMeta(id: ID!, key: String!): DeleteMeta+ updateMeta(id: ID!, input: MetaItemInput!): UpdateMetaassignNavigation(menu: ID, navigationType: NavigationType!): AssignNavigationmenuCreate(input: MenuCreateInput!): MenuCreatemenuDelete(id: ID!): MenuDelete@@ -2392,8 +2409,10 @@ interface Node {}interface ObjectWithMetadata {- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")}type Order implements Node, ObjectWithMetadata {@@ -2417,8 +2436,10 @@ type Order implements Node, ObjectWithMetadata {displayGrossPrices: Boolean!customerNote: String!weight: Weight- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")fulfillments: [Fulfillment]!lines: [OrderLine]!actions: [OrderAction]!@@ -3103,8 +3124,10 @@ type Product implements Node, ObjectWithMetadata {updatedAt: DateTimechargeTaxes: Boolean!weight: Weight- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")url: String!thumbnail(size: Int): Imagepricing: ProductPricingInfo@@ -3353,8 +3376,10 @@ type ProductType implements Node, ObjectWithMetadata {isShippingRequired: Boolean!isDigital: Boolean!weight: Weight- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")products(before: String, after: String, first: Int, last: Int): ProductCountableConnectiontaxRate: TaxRateTypetaxType: TaxType@@ -3493,8 +3518,10 @@ type ProductVariant implements Node, ObjectWithMetadata {product: Product!trackInventory: Boolean!weight: Weight- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")quantity: Int! @deprecated(reason: "This field will be removed in Saleor 2.11. Use the stock field instead.")quantityAllocated: Int @deprecated(reason: "This field will be removed in Saleor 2.11. Use the stock field instead.")stockQuantity: Int! @deprecated(reason: "This field will be removed in Saleor 2.11. Use the stock field instead.")@@ -3851,8 +3878,10 @@ type ServiceAccount implements Node, ObjectWithMetadata {created: DateTimeisActive: Booleantokens: [ServiceAccountToken]- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")permissions: [PermissionDisplay]name: String}@@ -4495,8 +4524,10 @@ type User implements Node, ObjectWithMetadata {dateJoined: DateTime!defaultShippingAddress: AddressdefaultBillingAddress: Address- privateMeta: [MetaStore]!- meta: [MetaStore]!+ privateMetadata: [MetaItem]!+ metadata: [MetaItem]!+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")addresses: [Address]checkout: CheckoutgiftCards(before: String, after: String, first: Int, last: Int): GiftCardCountableConnectiondiff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex a837f0ac42..2aa74561a7 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -7,6 +7,7 @@ from django.conf import settingsfrom django.core.serializers.json import DjangoJSONEncoderfrom django.db import transaction+from ..account.models import Userfrom ..checkout.models import Checkoutfrom ..order.actions import handle_fully_paid_orderfrom ..order.models import Order@@ -19,7 +20,6 @@ logger = logging.getLogger(__name__)GENERIC_TRANSACTION_ERROR = "Transaction was unsuccessful"ALLOWED_GATEWAY_KINDS = {choices[0] for choices in TransactionKind.CHOICES}-GATEWAYS_META_NAMESPACE = "payment-gateways"def create_payment_information(@@ -240,29 +240,21 @@ def gateway_postprocess(transaction, payment):payment.save(update_fields=changed_fields)-def fetch_customer_id(user, gateway):+def fetch_customer_id(user: User, gateway: str):"""Retrieve users customer_id stored for desired gateway."""- key = prepare_namespace_name(gateway)- gateway_config = {}- if hasattr(user, "get_private_meta"):- gateway_config = user.get_private_meta(- namespace=GATEWAYS_META_NAMESPACE, client=key- )- return gateway_config.get("customer_id", None)+ meta_key = prepare_key_for_gateway_customer_id(gateway)+ return user.get_private_meta(key=meta_key)-def store_customer_id(user, gateway, customer_id):+def store_customer_id(user: User, gateway: str, customer_id: str):"""Store customer_id in users private meta for desired gateway."""- user.store_private_meta(- namespace=GATEWAYS_META_NAMESPACE,- client=prepare_namespace_name(gateway),- item={"customer_id": customer_id},- )+ meta_key = prepare_key_for_gateway_customer_id(gateway)+ user.store_private_meta(items={meta_key: customer_id})user.save(update_fields=["private_meta"])-def prepare_namespace_name(s):- return s.strip().upper()+def prepare_key_for_gateway_customer_id(gateway_name: str) -> str:+ return (gateway_name.strip().upper()) + ".customer_id"def update_card_details(payment, gateway_response):diff --git a/tests/api/test_account_meta.py b/tests/api/test_account_meta.pyindex e30ae10661..a3145b4f93 100644--- a/tests/api/test_account_meta.py+++ b/tests/api/test_account_meta.py@@ -1,3 +1,4 @@+# Deprecated we should remove it in #5221import jsonimport graphene@@ -5,11 +6,11 @@ import pytestfrom tests.api.utils import assert_no_permission, get_graphql_content-PRIVATE_META_NAMESPACE = "TEST_NAMESPACE"-PUBLIC_META_NAMESPACE = "PUBLIC_NAMESPACE"+PRIVATE_META_NAMESPACE = ""+PUBLIC_META_NAMESPACE = ""-META_CLIENT = "TEST_PLUGIN"+META_CLIENT = ""PRIVATE_KEY = "name"PRIVATE_VALUE = "Bond"@@ -20,16 +21,8 @@ PUBLIC_VALUE = "42"@pytest.fixturedef customer_with_meta(customer_user):- customer_user.store_private_meta(- namespace=PRIVATE_META_NAMESPACE,- client=META_CLIENT,- item={PRIVATE_KEY: PRIVATE_VALUE},- )- customer_user.store_meta(- namespace=PUBLIC_META_NAMESPACE,- client=META_CLIENT,- item={PUBLIC_KEY: PUBLIC_VALUE},- )+ customer_user.store_private_meta(items={PRIVATE_KEY: PRIVATE_VALUE})+ customer_user.store_meta(items={PUBLIC_KEY: PUBLIC_VALUE})customer_user.save()return customer_user@@ -230,37 +223,6 @@ def test_clear_private_metadata_through_mutation(assert meta["clients"] == []-def test_clear_silently_private_metadata_from_nonexistent_client(- staff_api_client, permission_manage_users, customer_with_meta-):- user_id = graphene.Node.to_global_id("User", customer_with_meta.id)- WRONG_CLIENT = "WONG"- variables = {- "id": user_id,- "input": {- "namespace": PRIVATE_META_NAMESPACE,- "clientName": WRONG_CLIENT,- "key": PRIVATE_KEY,- },- }- response = staff_api_client.post_graphql(- CLEAR_PRIVATE_METADATA_MUTATION,- variables,- permissions=[permission_manage_users],- )- meta = get_graphql_content(response)["data"]["userClearPrivateMetadata"]["user"][- "privateMeta"- ][0]-- assert meta["namespace"] == PRIVATE_META_NAMESPACE- assert meta["clients"] == [- {- "metadata": [{"key": PRIVATE_KEY, "value": PRIVATE_VALUE}],- "name": META_CLIENT,- }- ]--MY_PUBLIC_META_QUERY = """{me {@@ -406,40 +368,6 @@ def test_staff_add_new_key_value_pair_to_metadata_using_mutation(assert meta["clients"] == [{"metadata": expected_metadata, "name": META_CLIENT}]-def test_add_new_namespace_metadata_using_mutation(- staff_api_client, customer_with_meta, permission_manage_users-):- NEW_KEY = "NEW_KEY"- NEW_VALUE = "NEW_VALUE"- NEW_NAMESPACE = "NEW_NAMESPACE"- NEW_CLIENT = "NEW_CLIENT"-- user_id = graphene.Node.to_global_id("User", customer_with_meta.id)- variables = {- "id": user_id,- "input": {- "namespace": NEW_NAMESPACE,- "clientName": NEW_CLIENT,- "key": NEW_KEY,- "value": NEW_VALUE,- },- }- response = staff_api_client.post_graphql(- UPDATE_METADATA_MUTATION, variables, permissions=[permission_manage_users]- )- meta = get_graphql_content(response)["data"]["userUpdateMetadata"]["user"]["meta"]-- assert meta[0]["namespace"] == NEW_NAMESPACE- assert meta[0]["clients"] == [- {"metadata": [{"key": NEW_KEY, "value": NEW_VALUE}], "name": NEW_CLIENT}- ]-- assert meta[1]["namespace"] == PUBLIC_META_NAMESPACE- assert meta[1]["clients"] == [- {"metadata": [{"key": PUBLIC_KEY, "value": PUBLIC_VALUE}], "name": META_CLIENT}- ]--CLEAR_METADATA_MUTATION = """mutation UserClearPrivateMetadata($id: ID!, $input: MetaPath!) {userClearMetadata(@@ -484,30 +412,6 @@ def test_staff_clear_metadata_through_mutation(assert meta["clients"] == []-def test_clear_silently_metadata_from_nonexistent_client(- staff_api_client, permission_manage_users, customer_with_meta-):- user_id = graphene.Node.to_global_id("User", customer_with_meta.id)- WRONG_CLIENT = "WONG"- variables = {- "id": user_id,- "input": {- "namespace": PUBLIC_META_NAMESPACE,- "clientName": WRONG_CLIENT,- "key": PUBLIC_KEY,- },- }- response = staff_api_client.post_graphql(- CLEAR_METADATA_MUTATION, variables, permissions=[permission_manage_users]- )- meta = get_graphql_content(response)["data"]["userClearMetadata"]["user"]["meta"][0]-- assert meta["namespace"] == PUBLIC_META_NAMESPACE- assert meta["clients"] == [- {"metadata": [{"key": PUBLIC_KEY, "value": PUBLIC_VALUE}], "name": META_CLIENT}- ]--@pytest.mark.parametrize("mutation", [UPDATE_METADATA_MUTATION, UPDATE_PRIVATE_METADATA_MUTATION])diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 81bec05f33..2a518c3303 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -1202,10 +1202,8 @@ def test_checkout_complete(checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.billing_address = address- checkout.store_meta(namespace="PUBLIC", client="PLUGIN", item={"accepted": "true"})- checkout.store_private_meta(- namespace="PRIVATE", client="PLUGIN", item={"accepted": "true"}- )+ checkout.store_meta(items={"accepted": "true"})+ checkout.store_private_meta(items={"accepted": "false"})checkout.save()checkout_line = checkout.lines.first()diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex 7711821c67..9a3c16588a 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -405,7 +405,7 @@ def clear_meta_variables(fulfillment):fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.id)return {"id": fulfillment_id,- "input": {"namespace": "test", "clientName": "client1", "key": "foo"},+ "input": {"namespace": "", "clientName": "", "key": "foo"},}@@ -415,9 +415,9 @@ def update_metadata_variables(staff_user, fulfillment):return {"id": fulfillment_id,"input": {- "namespace": "test",- "clientName": str(staff_user),- "key": "foo",+ "namespace": "",+ "clientName": "",+ "key": str(staff_user),"value": "bar",},}@@ -458,10 +458,10 @@ def test_fulfillment_update_metadata_user_has_permission(errors = content["data"]["orderFulfillmentUpdateMeta"]["errors"]assert len(errors) == 0fulfillment.refresh_from_db()- assert fulfillment.meta == {"test": {str(staff_user): {"foo": "bar"}}}+ assert fulfillment.meta == {str(staff_user): "bar"}-def test_fulfillment_update_private_metadata_user_has_no_permision(+def test_fulfillment_update_private_metadata_user_has_no_permission(staff_api_client,staff_user,update_private_metadata_mutation,@@ -499,7 +499,7 @@ def test_fulfillment_update_private_metadata_user_has_permission(errors = content["data"]["orderFulfillmentUpdatePrivateMeta"]["errors"]assert len(errors) == 0fulfillment.refresh_from_db()- assert fulfillment.private_meta == {"test": {str(staff_user): {"foo": "bar"}}}+ assert fulfillment.private_meta == {str(staff_user): "bar"}def test_fulfillment_clear_meta_user_has_no_permission(@@ -510,7 +510,7 @@ def test_fulfillment_clear_meta_user_has_no_permission(clear_metadata_mutation,):assert not staff_user.has_perm(OrderPermissions.MANAGE_ORDERS)- fulfillment.store_meta(namespace="test", client=staff_user, item={"foo": "bar"})+ fulfillment.store_meta(items={"foo": "bar"})fulfillment.save()response = staff_api_client.post_graphql(clear_metadata_mutation, clear_meta_variables@@ -528,7 +528,7 @@ def test_fulfillment_clear_meta_user_has_permission():staff_user.user_permissions.add(permission_manage_orders)assert staff_user.has_perm(OrderPermissions.MANAGE_ORDERS)- fulfillment.store_meta(namespace="test", client="client1", item={"foo": "bar"})+ fulfillment.store_meta(items={"foo": "bar"})fulfillment.save()fulfillment.refresh_from_db()response = staff_api_client.post_graphql(@@ -538,7 +538,7 @@ def test_fulfillment_clear_meta_user_has_permission(content = get_graphql_content(response)assert content.get("errors") is Nonefulfillment.refresh_from_db()- assert fulfillment.get_meta(namespace="test", client="client1") == {}+ assert not fulfillment.get_meta(key="foo")def test_fulfillment_clear_private_meta_user_has_no_permission(@@ -549,9 +549,7 @@ def test_fulfillment_clear_private_meta_user_has_no_permission(clear_private_metadata_mutation,):assert not staff_user.has_perm(OrderPermissions.MANAGE_ORDERS)- fulfillment.store_private_meta(- namespace="test", client="client1", item={"foo": "bar"}- )+ fulfillment.store_private_meta(items={"foo": "bar"})fulfillment.save()response = staff_api_client.post_graphql(clear_private_metadata_mutation, clear_meta_variables@@ -569,9 +567,7 @@ def test_fulfillment_clear_private_meta_user_has_permission():staff_user.user_permissions.add(permission_manage_orders)assert staff_user.has_perm(OrderPermissions.MANAGE_ORDERS)- fulfillment.store_private_meta(- namespace="test", client="client1", item={"foo": "bar"}- )+ fulfillment.store_private_meta(items={"foo": "bar"})fulfillment.save()fulfillment.refresh_from_db()response = staff_api_client.post_graphql(@@ -581,4 +577,4 @@ def test_fulfillment_clear_private_meta_user_has_permission(content = get_graphql_content(response)assert content.get("errors") is Nonefulfillment.refresh_from_db()- assert fulfillment.get_private_meta(namespace="test", client="client1") == {}+ assert not fulfillment.get_private_meta(key="foo")diff --git a/tests/api/test_meta.py b/tests/api/test_meta.pyindex 4076bf4a74..dbad26724b 100644--- a/tests/api/test_meta.py+++ b/tests/api/test_meta.py@@ -6,20 +6,15 @@ from saleor.core.error_codes import MetaErrorCodefrom saleor.core.models import ModelWithMetadatafrom tests.api.utils import get_graphql_content-PRIVATE_META_NAMESPACE = "TEST_NAMESPACE"-PUBLIC_META_NAMESPACE = "PUBLIC_NAMESPACE"+PRIVATE_KEY = "private_key"+PRIVATE_VALUE = "private_vale"-META_CLIENT = "TEST_PLUGIN"--PRIVATE_KEY = "name"-PRIVATE_VALUE = "Bond"--PUBLIC_KEY = "purpose"-PUBLIC_VALUE = "42"+PUBLIC_KEY = "key"+PUBLIC_VALUE = "value"UPDATE_PUBLIC_METADATA_MUTATION = """-mutation UpdatePublicMetadata($id: ID!, $input: MetaInput!) {+mutation UpdatePublicMetadata($id: ID!, $input: MetaItemInput!) {updateMeta(id: $idinput: $input@@ -29,15 +24,9 @@ mutation UpdatePublicMetadata($id: ID!, $input: MetaInput!) {code}item {- meta {- namespace- clients {- name- metadata {- key- value- }- }+ metadata{+ key+ value}...on %s{id@@ -49,23 +38,11 @@ mutation UpdatePublicMetadata($id: ID!, $input: MetaInput!) {def execute_update_public_metadata_for_item(- client,- permissions,- item_id,- item_type,- namespace=PUBLIC_META_NAMESPACE,- client_name=META_CLIENT,- key=PUBLIC_KEY,- value=PUBLIC_VALUE,+ client, permissions, item_id, item_type, key=PUBLIC_KEY, value=PUBLIC_VALUE,):variables = {"id": item_id,- "input": {- "namespace": namespace,- "clientName": client_name,- "key": key,- "value": value,- },+ "input": {"key": key, "value": value},}response = client.post_graphql(@@ -78,21 +55,12 @@ def execute_update_public_metadata_for_item(def item_contains_proper_public_metadata(- item_from_response,- item,- item_id,- namespace=PUBLIC_META_NAMESPACE,- client_name=META_CLIENT,- key=PUBLIC_KEY,- value=PUBLIC_VALUE,+ item_from_response, item, item_id, key=PUBLIC_KEY, value=PUBLIC_VALUE,):if item_from_response["id"] != item_id:return Falseitem.refresh_from_db()- meta = item.get_meta(namespace=namespace, client=client_name)- if meta.get(key, None) != value:- return False- return True+ return item.get_meta(key) == valuedef test_add_public_metadata_for_customer_as_staff(@@ -391,7 +359,7 @@ def test_add_public_metadata_for_service_account(def test_update_public_metadata_for_item(api_client, checkout):# given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ checkout.store_meta({PUBLIC_KEY: PUBLIC_VALUE})checkout.save(update_fields=["meta"])checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -443,25 +411,19 @@ def test_update_public_metadata_for_item_without_meta(api_client, address):CLEAR_PUBLIC_METADATA_MUTATION = """-mutation ClearPublicMetadata($id: ID!, $input: MetaPath!) {- clearMeta(+mutation DeletePublicMetadata($id: ID!, $key: String!) {+ deleteMeta(id: $id- input: $input+ key: $key) {metaErrors{fieldcode}item {- meta {- namespace- clients {- name- metadata {- key- value- }- }+ metadata{+ key+ value}...on %s{id@@ -473,17 +435,11 @@ mutation ClearPublicMetadata($id: ID!, $input: MetaPath!) {def execute_clear_public_metadata_for_item(- client,- permissions,- item_id,- item_type,- namespace=PUBLIC_META_NAMESPACE,- client_name=META_CLIENT,- key=PUBLIC_KEY,+ client, permissions, item_id, item_type, key=PUBLIC_KEY,):variables = {"id": item_id,- "input": {"namespace": namespace, "clientName": client_name, "key": key},+ "key": key,}response = client.post_graphql(@@ -496,30 +452,19 @@ def execute_clear_public_metadata_for_item(def item_without_public_metadata(- item_from_response,- item,- item_id,- namespace=PUBLIC_META_NAMESPACE,- client_name=META_CLIENT,- key=PUBLIC_KEY,- value=PUBLIC_VALUE,+ item_from_response, item, item_id, key=PUBLIC_KEY, value=PUBLIC_VALUE,):if item_from_response["id"] != item_id:return Falseitem.refresh_from_db()- meta = item.get_meta(namespace=namespace, client=client_name)- if meta.get(key, None) == value:- return False- return True+ return item.get_meta(key) != valuedef test_clear_public_metadata_for_customer_as_staff(staff_api_client, permission_manage_users, customer_user):# given- customer_user.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ customer_user.store_meta({PUBLIC_KEY: PUBLIC_VALUE})customer_user.save(update_fields=["meta"])customer_id = graphene.Node.to_global_id("User", customer_user.pk)@@ -530,7 +475,7 @@ def test_clear_public_metadata_for_customer_as_staff(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], customer_user, customer_id+ response["data"]["deleteMeta"]["item"], customer_user, customer_id)@@ -538,9 +483,7 @@ def test_clear_public_metadata_for_customer_as_service_account(service_account_api_client, permission_manage_users, customer_user):# given- customer_user.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ customer_user.store_meta({PUBLIC_KEY: PUBLIC_VALUE})customer_user.save(update_fields=["meta"])customer_id = graphene.Node.to_global_id("User", customer_user.pk)@@ -551,7 +494,7 @@ def test_clear_public_metadata_for_customer_as_service_account(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], customer_user, customer_id+ response["data"]["deleteMeta"]["item"], customer_user, customer_id)@@ -560,9 +503,7 @@ def test_clear_public_metadata_for_other_staff_as_staff():# givenassert admin_user.pk != staff_api_client.user.pk- admin_user.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ admin_user.store_meta({PUBLIC_KEY: PUBLIC_VALUE})admin_user.save(update_fields=["meta"])admin_id = graphene.Node.to_global_id("User", admin_user.pk)@@ -573,7 +514,7 @@ def test_clear_public_metadata_for_other_staff_as_staff(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], admin_user, admin_id+ response["data"]["deleteMeta"]["item"], admin_user, admin_id)@@ -581,9 +522,7 @@ def test_clear_public_metadata_for_staff_as_service_account(service_account_api_client, permission_manage_staff, admin_user):# given- admin_user.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ admin_user.store_meta({PUBLIC_KEY: PUBLIC_VALUE})admin_user.save(update_fields=["meta"])admin_id = graphene.Node.to_global_id("User", admin_user.pk)@@ -594,14 +533,14 @@ def test_clear_public_metadata_for_staff_as_service_account(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], admin_user, admin_id+ response["data"]["deleteMeta"]["item"], admin_user, admin_id)def test_clear_public_metadata_for_myself_as_customer(user_api_client):# givencustomer = user_api_client.user- customer.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ customer.store_meta({PUBLIC_KEY: PUBLIC_VALUE})customer.save(update_fields=["meta"])customer_id = graphene.Node.to_global_id("User", customer.pk)@@ -612,14 +551,14 @@ def test_clear_public_metadata_for_myself_as_customer(user_api_client):# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], customer, customer_id+ response["data"]["deleteMeta"]["item"], customer, customer_id)def test_clear_public_metadata_for_myself_as_staff(staff_api_client):# givenstaff = staff_api_client.user- staff.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ staff.store_meta({PUBLIC_KEY: PUBLIC_VALUE})staff.save(update_fields=["meta"])staff_id = graphene.Node.to_global_id("User", staff.pk)@@ -630,13 +569,13 @@ def test_clear_public_metadata_for_myself_as_staff(staff_api_client):# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], staff, staff_id+ response["data"]["deleteMeta"]["item"], staff, staff_id)def test_clear_public_metadata_for_checkout(api_client, checkout):# given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ checkout.store_meta({PUBLIC_KEY: PUBLIC_VALUE})checkout.save(update_fields=["meta"])checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -647,13 +586,13 @@ def test_clear_public_metadata_for_checkout(api_client, checkout):# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id+ response["data"]["deleteMeta"]["item"], checkout, checkout_id)def test_clear_public_metadata_for_order(api_client, order):# given- order.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ order.store_meta({PUBLIC_KEY: PUBLIC_VALUE})order.save(update_fields=["meta"])order_id = graphene.Node.to_global_id("Order", order.pk)@@ -664,7 +603,7 @@ def test_clear_public_metadata_for_order(api_client, order):# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], order, order_id+ response["data"]["deleteMeta"]["item"], order, order_id)@@ -672,9 +611,7 @@ def test_clear_public_metadata_for_attribute(staff_api_client, permission_manage_products, color_attribute):# given- color_attribute.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ color_attribute.store_meta({PUBLIC_KEY: PUBLIC_VALUE})color_attribute.save(update_fields=["meta"])attribute_id = graphene.Node.to_global_id("Attribute", color_attribute.pk)@@ -685,7 +622,7 @@ def test_clear_public_metadata_for_attribute(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], color_attribute, attribute_id+ response["data"]["deleteMeta"]["item"], color_attribute, attribute_id)@@ -693,7 +630,7 @@ def test_clear_public_metadata_for_category(staff_api_client, permission_manage_products, category):# given- category.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ category.store_meta({PUBLIC_KEY: PUBLIC_VALUE})category.save(update_fields=["meta"])category_id = graphene.Node.to_global_id("Category", category.pk)@@ -704,7 +641,7 @@ def test_clear_public_metadata_for_category(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], category, category_id+ response["data"]["deleteMeta"]["item"], category, category_id)@@ -712,9 +649,7 @@ def test_clear_public_metadata_for_collection(staff_api_client, permission_manage_products, collection):# given- collection.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ collection.store_meta({PUBLIC_KEY: PUBLIC_VALUE})collection.save(update_fields=["meta"])collection_id = graphene.Node.to_global_id("Collection", collection.pk)@@ -725,7 +660,7 @@ def test_clear_public_metadata_for_collection(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], collection, collection_id+ response["data"]["deleteMeta"]["item"], collection, collection_id)@@ -733,9 +668,7 @@ def test_clear_public_metadata_for_digital_content(staff_api_client, permission_manage_products, digital_content):# given- digital_content.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ digital_content.store_meta({PUBLIC_KEY: PUBLIC_VALUE})digital_content.save(update_fields=["meta"])digital_content_id = graphene.Node.to_global_id("DigitalContent", digital_content.pk@@ -751,7 +684,7 @@ def test_clear_public_metadata_for_digital_content(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], digital_content, digital_content_id+ response["data"]["deleteMeta"]["item"], digital_content, digital_content_id)@@ -759,9 +692,7 @@ def test_clear_public_metadata_for_fulfillment(staff_api_client, permission_manage_orders, fulfillment):# given- fulfillment.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ fulfillment.store_meta({PUBLIC_KEY: PUBLIC_VALUE})fulfillment.save(update_fields=["meta"])fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.pk)@@ -772,7 +703,7 @@ def test_clear_public_metadata_for_fulfillment(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], fulfillment, fulfillment_id+ response["data"]["deleteMeta"]["item"], fulfillment, fulfillment_id)@@ -780,7 +711,7 @@ def test_clear_public_metadata_for_product(staff_api_client, permission_manage_products, product):# given- product.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ product.store_meta({PUBLIC_KEY: PUBLIC_VALUE})product.save(update_fields=["meta"])product_id = graphene.Node.to_global_id("Product", product.pk)@@ -791,7 +722,7 @@ def test_clear_public_metadata_for_product(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], product, product_id+ response["data"]["deleteMeta"]["item"], product, product_id)@@ -799,9 +730,7 @@ def test_clear_public_metadata_for_product_type(staff_api_client, permission_manage_products, product_type):# given- product_type.store_meta(- PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE}- )+ product_type.store_meta({PUBLIC_KEY: PUBLIC_VALUE})product_type.save(update_fields=["meta"])product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)@@ -812,7 +741,7 @@ def test_clear_public_metadata_for_product_type(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], product_type, product_type_id+ response["data"]["deleteMeta"]["item"], product_type, product_type_id)@@ -820,7 +749,7 @@ def test_clear_public_metadata_for_product_variant(staff_api_client, permission_manage_products, variant):# given- variant.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ variant.store_meta({PUBLIC_KEY: PUBLIC_VALUE})variant.save(update_fields=["meta"])variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)@@ -831,7 +760,7 @@ def test_clear_public_metadata_for_product_variant(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], variant, variant_id+ response["data"]["deleteMeta"]["item"], variant, variant_id)@@ -853,7 +782,7 @@ def test_clear_public_metadata_for_service_account(# thenassert item_without_public_metadata(- response["data"]["clearMeta"]["item"], service_account, service_account_id+ response["data"]["deleteMeta"]["item"], service_account, service_account_id)@@ -867,7 +796,7 @@ def test_clear_public_metadata_for_non_exist_item(api_client):)# then- errors = response["data"]["clearMeta"]["metaErrors"]+ errors = response["data"]["deleteMeta"]["metaErrors"]assert errors[0]["field"] == "id"assert errors[0]["code"] == MetaErrorCode.NOT_FOUND.name@@ -885,14 +814,14 @@ def test_clear_public_metadata_for_item_without_meta(api_client, address):)# then- errors = response["data"]["clearMeta"]["metaErrors"]+ errors = response["data"]["deleteMeta"]["metaErrors"]assert errors[0]["field"] == "id"assert errors[0]["code"] == MetaErrorCode.INVALID.namedef test_clear_public_metadata_for_not_exist_key(api_client, checkout):# given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})+ checkout.store_meta({PUBLIC_KEY: PUBLIC_VALUE})checkout.save(update_fields=["meta"])checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -903,51 +832,13 @@ def test_clear_public_metadata_for_not_exist_key(api_client, checkout):# thenassert item_contains_proper_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id- )---def test_clear_public_metadata_for_not_exist_client(api_client, checkout):- # given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})- checkout.save(update_fields=["meta"])- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)-- # when- response = execute_clear_public_metadata_for_item(- api_client, None, checkout_id, "Checkout", client_name="Not-exits"- )-- # then- assert item_contains_proper_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id- )---def test_clear_public_metadata_for_not_exist_namespace(api_client, checkout):- # given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})- checkout.save(update_fields=["meta"])- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)-- # when- response = execute_clear_public_metadata_for_item(- api_client, None, checkout_id, "Checkout", namespace="Not-exits"- )-- # then- assert item_contains_proper_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id+ response["data"]["deleteMeta"]["item"], checkout, checkout_id)def test_clear_public_metadata_for_one_key(api_client, checkout):# given- checkout.store_meta(- PUBLIC_META_NAMESPACE,- META_CLIENT,- {PUBLIC_KEY: PUBLIC_VALUE, "to_clear": PUBLIC_VALUE},- )+ checkout.store_meta({PUBLIC_KEY: PUBLIC_VALUE, "to_clear": PUBLIC_VALUE},)checkout.save(update_fields=["meta"])checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -958,24 +849,8 @@ def test_clear_public_metadata_for_one_key(api_client, checkout):# thenassert item_contains_proper_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id+ response["data"]["deleteMeta"]["item"], checkout, checkout_id)assert item_without_public_metadata(- response["data"]["clearMeta"]["item"], checkout, checkout_id, key="to_clear"+ response["data"]["deleteMeta"]["item"], checkout, checkout_id, key="to_clear")---def test_clear_public_metadata_remove_empty_client(api_client, checkout):- # given- checkout.store_meta(PUBLIC_META_NAMESPACE, META_CLIENT, {PUBLIC_KEY: PUBLIC_VALUE})- checkout.store_meta(PUBLIC_META_NAMESPACE, "Client2", {PUBLIC_KEY: PUBLIC_VALUE})- checkout.save(update_fields=["meta"])- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)-- # when- execute_clear_public_metadata_for_item(api_client, None, checkout_id, "Checkout")-- # then- checkout.refresh_from_db()- assert not checkout.get_meta(PUBLIC_META_NAMESPACE, META_CLIENT)- assert checkout.get_meta(PUBLIC_META_NAMESPACE, "Client2")diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 30d52a1e34..ef98b826cc 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -2659,7 +2659,7 @@ def test_user_does_not_need_permission_to_update_meta(errors = content["data"]["orderUpdateMeta"]["errors"]assert len(errors) == 0order.refresh_from_db()- assert order.get_meta(namespace="test", client="client1") == {"foo": "bar"}+ assert order.get_meta("foo") == "bar"def test_user_with_permission_can_update_private_meta(@@ -2679,7 +2679,7 @@ def test_user_with_permission_can_update_private_meta(errors = content["data"]["orderUpdatePrivateMeta"]["errors"]assert len(errors) == 0order.refresh_from_db()- assert order.get_private_meta(namespace="test", client="client1") == {"foo": "bar"}+ assert order.get_private_meta("foo") == "bar"@pytest.fixture@@ -2724,17 +2724,15 @@ def clear_meta_private_variables(order):"input": {"namespace": "testPrivate","clientName": "clientPrivate1",- "key": "foo",+ "key": "foofoo",},}@pytest.fixturedef order_with_meta(order):- order.store_meta(namespace="test", client="client1", item={"foo": "bar"})- order.store_private_meta(- namespace="testPrivate", client="clientPrivate1", item={"foo": "bar"}- )+ order.store_meta(items={"foo": "bar"})+ order.store_private_meta(items={"foofoo": "barbar"})order.save()return order@@ -2773,8 +2771,7 @@ def test_user_with_permission_can_clear_meta(errors = content["data"]["orderClearMeta"]["errors"]assert len(errors) == 0order_with_meta.refresh_from_db()- current_meta = order_with_meta.get_meta(namespace="test", client="client1")- assert current_meta == {}+ assert not order_with_meta.get_meta("foo")def test_user_with_permission_can_clear_private_meta(@@ -2795,5 +2792,4 @@ def test_user_with_permission_can_clear_private_meta(errors = content["data"]["orderClearPrivateMeta"]["errors"]assert len(errors) == 0order_with_meta.refresh_from_db()- current_meta = order_with_meta.get_private_meta(namespace="test", client="client1")- assert current_meta == {}+ assert not order_with_meta.get_private_meta(key="foofoo")diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex dbe73ab0b3..62797aba83 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -582,11 +582,8 @@ def dummy_customer_id():def test_store_payment_gateway_meta(customer_user, braintree_customer_id):gateway_name = "braintree"- META = {- "payment-gateways": {- gateway_name.upper(): {"customer_id": braintree_customer_id}- }- }+ meta_key = "BRAINTREE.customer_id"+ META = {meta_key: braintree_customer_id}store_customer_id(customer_user, gateway_name, braintree_customer_id)assert customer_user.private_meta == METAcustomer_user.refresh_from_db()diff --git a/tests/extensions/plugins/test_vatlayer.py b/tests/extensions/plugins/test_vatlayer.pyindex e5eff750cb..f557c51ddb 100644--- a/tests/extensions/plugins/test_vatlayer.py+++ b/tests/extensions/plugins/test_vatlayer.py@@ -433,7 +433,8 @@ def test_apply_taxes_to_product(vatlayer, settings, variant, discount_info):country = Country("PL")manager = get_extensions_manager()variant.product.meta = {- "taxes": {"vatlayer": {"code": "standard", "description": "standard"}}+ "vatlayer.code": "standard",+ "vatlayer.description": "standard",}price = manager.apply_taxes_to_product(variant.product, variant.get_price([discount_info]), country