Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add new extension fields and deprecate legacy enum-based fields (#18397)
Lukasz Ostrowski3d23b7612e23
diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.pyindex f54ef574ed..7ef8c83521 100644--- a/saleor/app/installation_utils.py+++ b/saleor/app/installation_utils.py@@ -241,10 +241,10 @@ def install_app(app_installation: AppInstallation, activate: bool = False):app.permissions.set(app_installation.permissions.all())for extension_data in manifest_data.get("extensions", []):- # Manifest is already "clean" so values are snake case+ # Manifest is already "clean" so values use serialization aliases (camelCase)options = extension_data.get("options", {})- new_tab_target = options.get("new_tab_target")- widget_target = options.get("widget_target")+ new_tab_target = options.get("newTabTarget")+ widget_target = options.get("widgetTarget")# Ensure proper extraction of the method values from the optionshttp_target_method = None@@ -270,6 +270,7 @@ def install_app(app_installation: AppInstallation, activate: bool = False):mount=extension_data.get("mount"),target=extension_data.get("target", AppExtensionTarget.POPUP),http_target_method=http_target_method,+ settings=extension_data.get("options"),)extension.permissions.set(extension_data.get("permissions", []))diff --git a/saleor/app/manifest_validations.py b/saleor/app/manifest_validations.pyindex c67f7ec14b..cc13d769bf 100644--- a/saleor/app/manifest_validations.py+++ b/saleor/app/manifest_validations.py@@ -257,7 +257,9 @@ def _clean_extension_options(extension, errors):)# Update the extension with the validated options- extension["options"] = validated_options.model_dump(exclude_none=True)+ extension["options"] = validated_options.model_dump(+ exclude_none=True, by_alias=True+ )except (ValidationError, PydanticValidationError) as e:errors["extensions"].append(ValidationError(diff --git a/saleor/app/migrations/0033_appextension_settings.py b/saleor/app/migrations/0033_appextension_settings.pynew file mode 100644index 0000000000..b031831d2d--- /dev/null+++ b/saleor/app/migrations/0033_appextension_settings.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.5 on 2025-10-28 12:30++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("app", "0032_appextension_http_target_method_and_more"),+ ]++ operations = [+ migrations.AddField(+ model_name="appextension",+ name="settings",+ field=models.JSONField(blank=True, db_default={}, default=dict),+ ),+ ]diff --git a/saleor/app/models.py b/saleor/app/models.pyindex c560428a45..b6e2e93ca4 100644--- a/saleor/app/models.py+++ b/saleor/app/models.py@@ -173,6 +173,7 @@ class AppExtension(models.Model):null=True,choices=AppExtensionHttpMethod.CHOICES,)+ settings = models.JSONField(blank=True, default=dict, db_default={})class AppInstallation(Job):diff --git a/saleor/app/tests/test_validators.py b/saleor/app/tests/test_validators.pyindex 2384e76d5a..4b261263ed 100644--- a/saleor/app/tests/test_validators.py+++ b/saleor/app/tests/test_validators.py@@ -293,8 +293,8 @@ def test_clean_extension_options_valid_widget_options():assert "extensions" in errorsassert len(errors["extensions"]) == 0assert "options" in extension- assert "widget_target" in extension["options"]- assert extension["options"]["widget_target"]["method"] == "POST"+ assert "widgetTarget" in extension["options"]+ assert extension["options"]["widgetTarget"]["method"] == "POST"def test_clean_extension_options_valid_new_tab_options():@@ -312,8 +312,8 @@ def test_clean_extension_options_valid_new_tab_options():assert "extensions" in errorsassert len(errors["extensions"]) == 0assert "options" in extension- assert "new_tab_target" in extension["options"]- assert extension["options"]["new_tab_target"]["method"] == "GET"+ assert "newTabTarget" in extension["options"]+ assert extension["options"]["newTabTarget"]["method"] == "GET"def test_clean_extension_options_both_targets():diff --git a/saleor/app/validators.py b/saleor/app/validators.pyindex ca0bf7b46f..bfc4b56196 100644--- a/saleor/app/validators.py+++ b/saleor/app/validators.py@@ -82,6 +82,7 @@ class AppExtensionOptions(BaseModel):NewTabTargetOptions | None,Field(validation_alias="newTabTarget",+ serialization_alias="newTabTarget",description="Settings for extension target NEW_TAB",),] = None@@ -89,6 +90,7 @@ class AppExtensionOptions(BaseModel):WidgetTargetOptions | None,Field(validation_alias="widgetTarget",+ serialization_alias="widgetTarget",description="Settings for extension target WIDGET",),] = Nonediff --git a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.pyindex d015109f95..5c8a695b5e 100644--- a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py+++ b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py@@ -47,6 +47,9 @@ mutation AppFetchManifest(urlmounttarget+ mountName+ targetName+ settingspermissions{codename@@ -682,6 +685,109 @@ def test_app_fetch_manifest_with_extensions(assert extension["mount"] == AppExtensionMountEnum.PRODUCT_OVERVIEW_CREATE.nameassert extension["target"] == AppExtensionTargetEnum.POPUP.name+ assert extension["mountName"] == "PRODUCT_OVERVIEW_CREATE"+ assert extension["targetName"] == "POPUP"++ assert extension["settings"] == {}+++def test_app_fetch_manifest_with_widget_extension_settings(+ staff_api_client, app_manifest, permission_manage_apps, monkeypatch+):+ # given+ manifest_url = "http://localhost:3000/manifest"++ app_manifest["extensions"] = [+ {+ "permissions": ["MANAGE_PRODUCTS"],+ "label": "Product Widget",+ "url": "http://127.0.0.1:8080/widget",+ "mount": AppExtensionMountEnum.PRODUCT_DETAILS_WIDGETS.name,+ "target": AppExtensionTargetEnum.WIDGET.name,+ "options": {"widgetTarget": {"method": "POST"}},+ }+ ]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest++ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))++ query = APP_FETCH_MANIFEST_MUTATION+ variables = {+ "manifest_url": manifest_url,+ }++ # when+ response = staff_api_client.post_graphql(+ query, variables=variables, permissions=[permission_manage_apps]+ )++ # then+ content = get_graphql_content(response)+ errors = content["data"]["appFetchManifest"]["errors"]+ manifest = content["data"]["appFetchManifest"]["manifest"]++ extensions = manifest["extensions"] if manifest else []++ assert not errors, f"Expected no errors, got: {errors}"+ assert len(extensions) == 1++ extension = extensions[0]+ assert extension["label"] == "Product Widget"+ assert extension["target"] == AppExtensionTargetEnum.WIDGET.name++ assert extension["settings"] == {"widgetTarget": {"method": "POST"}}+++def test_app_fetch_manifest_with_new_tab_extension_settings(+ staff_api_client, app_manifest, permission_manage_apps, monkeypatch+):+ # given+ manifest_url = "http://localhost:3000/manifest"++ app_manifest["permissions"] = ["MANAGE_ORDERS"]+ app_manifest["extensions"] = [+ {+ "permissions": ["MANAGE_ORDERS"],+ "label": "Order Details",+ "url": "https://127.0.0.1:8080/orders",+ "mount": AppExtensionMountEnum.ORDER_DETAILS_MORE_ACTIONS.name,+ "target": AppExtensionTargetEnum.NEW_TAB.name,+ "options": {"newTabTarget": {"method": "GET"}},+ }+ ]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest++ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))++ query = APP_FETCH_MANIFEST_MUTATION+ variables = {+ "manifest_url": manifest_url,+ }++ # when+ response = staff_api_client.post_graphql(+ query, variables=variables, permissions=[permission_manage_apps]+ )++ # then+ content = get_graphql_content(response)+ errors = content["data"]["appFetchManifest"]["errors"]+ manifest = content["data"]["appFetchManifest"]["manifest"]+ extensions = manifest["extensions"]++ assert not errors+ assert len(extensions) == 1++ extension = extensions[0]+ assert extension["label"] == "Order Details"+ assert extension["target"] == AppExtensionTargetEnum.NEW_TAB.name++ assert extension["settings"] == {"newTabTarget": {"method": "GET"}}+def test_app_fetch_manifest_with_required_saleor_version(staff_api_client, app_manifest, permission_manage_apps, monkeypatchdiff --git a/saleor/graphql/app/tests/queries/test_app_extension.py b/saleor/graphql/app/tests/queries/test_app_extension.pyindex 2c404dec66..300029908c 100644--- a/saleor/graphql/app/tests/queries/test_app_extension.py+++ b/saleor/graphql/app/tests/queries/test_app_extension.py@@ -13,11 +13,14 @@ query ($id: ID!){urlmounttarget+ mountName+ targetNameidaccessTokenpermissions{code}+ settingsoptions {... on AppExtensionOptionsWidget{widgetTarget {@@ -71,6 +74,12 @@ def test_app_extension_staff_user(app, staff_api_client, permission_manage_produassert extension_data["options"]["widgetTarget"]["method"] == "POST"+ assert extension_data["settings"] is not None+ assert extension_data["settings"]["widgetTarget"]["method"] == "POST"++ assert extension_data["mountName"] == "PRODUCT_OVERVIEW_MORE_ACTIONS"+ assert extension_data["targetName"] == "WIDGET"+def test_app_extension_by_app(app, app_api_client, permission_manage_products):# given@@ -103,6 +112,11 @@ def test_app_extension_by_app(app, app_api_client, permission_manage_products):permission_code = extension_data["permissions"][0]["code"].lower()assert app_extension.permissions.first().codename == permission_code+ assert extension_data["settings"] == {}++ assert extension_data["mountName"] == "PRODUCT_OVERVIEW_MORE_ACTIONS"+ assert extension_data["targetName"] == "POPUP"+def test_app_extensions_app_removed_app(staff_api_client, removed_app, permission_manage_products@@ -515,8 +529,13 @@ def test_app_extension_type_options(assert extension_data["target"] == target.upper()+ assert extension_data["mountName"] == "ORDER_DETAILS_WIDGETS"+ assert extension_data["targetName"] == app_extension.target.upper()+if target == AppExtensionTarget.NEW_TAB:assert extension_data["options"]["newTabTarget"]["method"] == method+ assert extension_data["settings"]["newTabTarget"]["method"] == methodif target == AppExtensionTarget.WIDGET:assert extension_data["options"]["widgetTarget"]["method"] == method+ assert extension_data["settings"]["widgetTarget"]["method"] == methoddiff --git a/saleor/graphql/app/tests/queries/test_app_extensions.py b/saleor/graphql/app/tests/queries/test_app_extensions.pyindex a6c494e272..fe17b65dfe 100644--- a/saleor/graphql/app/tests/queries/test_app_extensions.py+++ b/saleor/graphql/app/tests/queries/test_app_extensions.py@@ -15,6 +15,9 @@ query ($filter: AppExtensionFilterInput){urlmounttarget+ mountName+ targetName+ settingsidaccessTokenoptions {@@ -82,6 +85,8 @@ def test_app_extensions(staff_api_client, app, permission_manage_products):decode_token["permissions"] = ["MANAGE_PRODUCTS"]assert extension_data["options"]["widgetTarget"]["method"] == "POST"+ assert extension_data["mountName"] == "PRODUCT_OVERVIEW_MORE_ACTIONS"+ assert extension_data["targetName"] == "WIDGET"def test_app_extensions_app_not_active(diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.pyindex 34fee0e7fe..4914fbbab5 100644--- a/saleor/graphql/app/types.py+++ b/saleor/graphql/app/types.py@@ -30,7 +30,7 @@ from ..core.dataloaders import DataLoaderfrom ..core.descriptions import ADDED_IN_319, ADDED_IN_321, ADDED_IN_322from ..core.doc_category import DOC_CATEGORY_APPSfrom ..core.federation import federated_entity, resolve_federation_references-from ..core.scalars import DateTime+from ..core.scalars import JSON, DateTimefrom ..core.types import (BaseEnum,BaseObjectType,@@ -117,12 +117,35 @@ class AppManifestExtension(BaseObjectType):url = graphene.String(description="URL of a view where extension's iframe is placed.", required=True)+ # TODO Remove in 3.23mount = AppExtensionMountEnum(description="Place where given extension will be mounted.",required=True,+ deprecation_reason="Use `mountName` instead.",)+ # TODO Remove in 3.23target = AppExtensionTargetEnum(- description="Type of way how app extension will be opened.", required=True+ description="Type of way how app extension will be opened.",+ required=True,+ deprecation_reason="Use `targetName` instead.",+ )++ mount_name = graphene.String(+ description="Name of the extension mount point in the dashboard. Replaces `mount`"+ + ADDED_IN_322,+ required=True,+ )++ target_name = graphene.String(+ description="Name of the extension target in the dashboard. Replaces `target`"+ + ADDED_IN_322,+ required=True,+ )++ settings = graphene.Field(+ JSON,+ description="App extension settings. Replaces options field." + ADDED_IN_322,+ required=True,)class Meta:@@ -137,17 +160,33 @@ class AppManifestExtension(BaseObjectType):"""Return an extension URL."""return resolve_app_extension_url(root)+ @staticmethod+ def resolve_target_name(root, _info: ResolveInfo):+ # Temporary upper(), but TODO return it directly from DB once we migrate DB+ return (root.get("target") or "POPUP").upper()++ @staticmethod+ def resolve_mount_name(root, _info: ResolveInfo):+ # Temporary upper(), but TODO return it directly from DB once we migrate DB+ return root["mount"].upper()++ @staticmethod+ def resolve_settings(root, _info: ResolveInfo):+ return root.get("options") or {}+class HttpMethod(BaseEnum):POST = AppExtensionHttpMethod.POSTGET = AppExtensionHttpMethod.GET+# TODO Remove in 3.23class NewTabTargetOptions(BaseObjectType):method = graphene.Field(HttpMethod,required=True,description="HTTP method for New Tab target (GET or POST)",+ deprecation_reason="Use `settings` field directly.",)class Meta:@@ -155,11 +194,13 @@ class NewTabTargetOptions(BaseObjectType):doc_category = DOC_CATEGORY_APPS+# TODO Remove in 3.23class WidgetTargetOptions(BaseObjectType):method = graphene.Field(HttpMethod,required=True,description="HTTP method for Widget target (GET or POST)",+ deprecation_reason="Use `settings` field directly.",)class Meta:@@ -167,11 +208,13 @@ class WidgetTargetOptions(BaseObjectType):doc_category = DOC_CATEGORY_APPS+# TODO Remove in 3.23class AppExtensionOptionsWidget(BaseObjectType):widget_target = graphene.Field(WidgetTargetOptions,description="Options for displaying a Widget",required=False,+ deprecation_reason="Use `settings` field directly.",)class Meta:@@ -179,11 +222,13 @@ class AppExtensionOptionsWidget(BaseObjectType):doc_category = DOC_CATEGORY_APPS+# TODO Remove in 3.23class AppExtensionOptionsNewTab(BaseObjectType):new_tab_target = graphene.Field(NewTabTargetOptions,description="Options controlling behavior of the NEW_TAB extension target",required=False,+ deprecation_reason="Use `settings` field directly.",)class Meta:@@ -191,6 +236,7 @@ class AppExtensionOptionsNewTab(BaseObjectType):doc_category = DOC_CATEGORY_APPS+# TODO Remove in 3.23class AppExtensionPossibleOptions(graphene.Union):class Meta:types = (AppExtensionOptionsWidget, AppExtensionOptionsNewTab)@@ -209,6 +255,7 @@ class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):options = graphene.Field(AppExtensionPossibleOptions,description="App extension options." + ADDED_IN_322,+ deprecation_reason="Use `settings` field directly.",)class Meta:@@ -233,6 +280,16 @@ class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):def resolve_target(root, _info: ResolveInfo):return root.target+ @staticmethod+ def resolve_mount_name(root: models.AppExtension, _info: ResolveInfo):+ # Temporary upper(), but TODO return it directly from DB once we migrate DB+ return root.mount.upper()++ @staticmethod+ def resolve_target_name(root: models.AppExtension, _info: ResolveInfo):+ # Temporary upper(), but TODO return it directly from DB once we migrate DB+ return root.target.upper()+@staticmethod@app_promise_callbackdef resolve_app(root, info: ResolveInfo, app_requestor):@@ -287,6 +344,28 @@ class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):return None+ # TODO Return settings directly from the DB+ @staticmethod+ def resolve_settings(root: models.AppExtension, _info: ResolveInfo):+ """Return app extension settings as plain JSON with same structure as options."""+ http_method = root.http_target_method++ if root.target == AppExtensionTarget.WIDGET:+ return {+ "widgetTarget": {+ "method": http_method,+ }+ }++ if root.target == AppExtensionTarget.NEW_TAB:+ return {+ "newTabTarget": {+ "method": http_method,+ }+ }++ return {}+class AppExtensionCountableConnection(CountableConnection):class Meta:diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 48ff61ebb0..6881fa0933 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3026,10 +3026,31 @@ type AppExtension implements Node @doc(category: "Apps") {url: String!"""Place where given extension will be mounted."""- mount: AppExtensionMountEnum!+ mount: AppExtensionMountEnum! @deprecated(reason: "Use `mountName` instead.")"""Type of way how app extension will be opened."""- target: AppExtensionTargetEnum!+ target: AppExtensionTargetEnum! @deprecated(reason: "Use `targetName` instead.")++ """+ Name of the extension mount point in the dashboard. Replaces `mount`++ Added in Saleor 3.22.+ """+ mountName: String!++ """+ Name of the extension target in the dashboard. Replaces `target`++ Added in Saleor 3.22.+ """+ targetName: String!++ """+ App extension settings. Replaces options field.++ Added in Saleor 3.22.+ """+ settings: JSON!"""The app assigned to app extension."""app: App!@@ -3042,7 +3063,7 @@ type AppExtension implements Node @doc(category: "Apps") {Added in Saleor 3.22."""- options: AppExtensionPossibleOptions+ options: AppExtensionPossibleOptions @deprecated(reason: "Use `settings` field directly.")}"""All places where app extension can be mounted."""@@ -3111,18 +3132,20 @@ enum AppExtensionTargetEnum @doc(category: "Apps") {WIDGET}+scalar JSON+union AppExtensionPossibleOptions = AppExtensionOptionsWidget | AppExtensionOptionsNewTab"""Represents the options for an app extension."""type AppExtensionOptionsWidget @doc(category: "Apps") {"""Options for displaying a Widget"""- widgetTarget: WidgetTargetOptions+ widgetTarget: WidgetTargetOptions @deprecated(reason: "Use `settings` field directly.")}"""Represents the WIDGET target options for an app extension."""type WidgetTargetOptions @doc(category: "Apps") {"""HTTP method for Widget target (GET or POST)"""- method: HttpMethod!+ method: HttpMethod! @deprecated(reason: "Use `settings` field directly.")}enum HttpMethod {@@ -3133,13 +3156,13 @@ enum HttpMethod {"""Represents the options for an app extension."""type AppExtensionOptionsNewTab @doc(category: "Apps") {"""Options controlling behavior of the NEW_TAB extension target"""- newTabTarget: NewTabTargetOptions+ newTabTarget: NewTabTargetOptions @deprecated(reason: "Use `settings` field directly.")}"""Represents the NEW_TAB target options for an app extension."""type NewTabTargetOptions @doc(category: "Apps") {"""HTTP method for New Tab target (GET or POST)"""- method: HttpMethod!+ method: HttpMethod! @deprecated(reason: "Use `settings` field directly.")}"""Represents the app's brand data."""@@ -12701,8 +12724,6 @@ enum TokenizedPaymentFlowEnum @doc(category: "Payments") {INTERACTIVE}-scalar JSON-"""Represents an problem in the checkout."""union CheckoutProblem = CheckoutLineProblemInsufficientStock | CheckoutLineProblemVariantNotAvailable@@ -29843,10 +29864,31 @@ type AppManifestExtension @doc(category: "Apps") {url: String!"""Place where given extension will be mounted."""- mount: AppExtensionMountEnum!+ mount: AppExtensionMountEnum! @deprecated(reason: "Use `mountName` instead.")"""Type of way how app extension will be opened."""- target: AppExtensionTargetEnum!+ target: AppExtensionTargetEnum! @deprecated(reason: "Use `targetName` instead.")++ """+ Name of the extension mount point in the dashboard. Replaces `mount`++ Added in Saleor 3.22.+ """+ mountName: String!++ """+ Name of the extension target in the dashboard. Replaces `target`++ Added in Saleor 3.22.+ """+ targetName: String!++ """+ App extension settings. Replaces options field.++ Added in Saleor 3.22.+ """+ settings: JSON!}type AppManifestWebhook @doc(category: "Apps") {