Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use CONFIG_STRUCTURE to get fields type
Mira Szewczyk201ffce039f3
diff --git a/saleor/extensions/base_plugin.py b/saleor/extensions/base_plugin.pyindex 9e66770ea4..7f8f54b9d1 100644--- a/saleor/extensions/base_plugin.py+++ b/saleor/extensions/base_plugin.py@@ -322,17 +322,20 @@ class BasePlugin:def _update_config_items(cls, configuration_to_update: List[dict], current_config: List[dict]):-+ config_structure = (+ cls.CONFIG_STRUCTURE if cls.CONFIG_STRUCTURE is not None else {}+ )for config_item in current_config:for config_item_to_update in configuration_to_update:- if config_item["name"] == config_item_to_update.get("name"):+ config_item_name = config_item_to_update.get("name")+ if config_item["name"] == config_item_name:new_value = config_item_to_update.get("value")# The frontend can send all configuration fields with# all secrets as **...**, we have to omit all secrets which# weren't modifiedif new_value == cls.REDACTED_FORM:continue- item_type = config_item.get("type")+ item_type = config_structure.get(config_item_name, {}).get("type")if item_type == ConfigurationTypeField.BOOLEAN and not isinstance(new_value, bool):diff --git a/tests/api/test_extensions.py b/tests/api/test_extensions.pyindex ca4726f21f..ea86ddf8ea 100644--- a/tests/api/test_extensions.py+++ b/tests/api/test_extensions.py@@ -10,6 +10,23 @@ from tests.api.utils import get_graphql_contentclass PluginSample(BasePlugin):PLUGIN_NAME = "PluginSample"+ CONFIG_STRUCTURE = {+ "Username": {+ "type": ConfigurationTypeField.STRING,+ "help_text": "Username input field",+ "label": "Username",+ },+ "Password": {+ "type": ConfigurationTypeField.STRING,+ "help_text": "Password input field",+ "label": "Password",+ },+ "Use sandbox": {+ "type": ConfigurationTypeField.BOOLEAN,+ "help_text": "Use sandbox",+ "label": "Use sandbox",+ },+ }@classmethoddef get_plugin_configuration(cls, queryset) -> "PluginConfiguration":