Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Let apps declare deprecation to guide migration (#19814) (#19815)

Lukasz Ostrowski6fcdad6e5fe5
diff --git a/saleor/app/error_codes.py b/saleor/app/error_codes.py
index 77c125e30c..f167dce2be 100644
--- a/saleor/app/error_codes.py
+++ b/saleor/app/error_codes.py
@@ -34,3 +34,9 @@ class AppProblemDismissErrorCode(Enum):
REQUIRED = "required"
NOT_FOUND = "not_found"
OUT_OF_SCOPE_APP = "out_of_scope_app"
+
+
+class AppSelfUpdateErrorCode(Enum):
+ GRAPHQL_ERROR = "graphql_error"
+ INVALID = "invalid"
+ REQUIRED = "required"
diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.py
index c8e0f71e96..5672b41254 100644
--- a/saleor/app/installation_utils.py
+++ b/saleor/app/installation_utils.py
@@ -29,6 +29,7 @@ from .error_codes import AppErrorCode
from .manifest_validations import clean_manifest_data
from .models import App, AppExtension, AppInstallation, AppToken
from .types import DEFAULT_APP_TARGET, AppType
+from .utils import normalize_deprecation_reason
MAX_ICON_FILE_SIZE = 1024 * 1024 * 10 # 10MB
@@ -263,6 +264,11 @@ def install_app(
audience=manifest_data.get("audience"),
is_installed=False,
author=manifest_data.get("author"),
+ # `clean_manifest_data` validates against `ManifestSchema` but discards
+ # the result, so the schema's normalization never reaches this dict.
+ deprecation_reason=normalize_deprecation_reason(
+ manifest_data.get("deprecationReason")
+ ),
)
app.permissions.set(app_installation.permissions.all())
diff --git a/saleor/app/manifest_schema.py b/saleor/app/manifest_schema.py
index f799063826..ccf4c8cf85 100644
--- a/saleor/app/manifest_schema.py
+++ b/saleor/app/manifest_schema.py
@@ -108,6 +108,7 @@ class ManifestSchema(BaseModel):
audience: str | None = None
required_saleor_version: str | None = None
author: str | None = None
+ deprecation_reason: str | None = None
brand: ManifestBrandSchema | None = None
extensions: DefaultIfNone[list[ManifestExtensionSchema]] = []
webhooks: DefaultIfNone[list[ManifestWebhookSchema]] = []
diff --git a/saleor/app/migrations/0042_app_deprecation_reason.py b/saleor/app/migrations/0042_app_deprecation_reason.py
new file mode 100644
index 0000000000..a4052a636d
--- /dev/null
+++ b/saleor/app/migrations/0042_app_deprecation_reason.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.2.16 on 2026-09-22 14:23
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("app", "0041_widen_manifest_url"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="app",
+ name="deprecation_reason",
+ field=models.CharField(blank=True, max_length=2048, null=True),
+ ),
+ ]
diff --git a/saleor/app/migrations/0043_merge_20260923_0819.py b/saleor/app/migrations/0043_merge_20260923_0819.py
new file mode 100644
index 0000000000..1342c33f86
--- /dev/null
+++ b/saleor/app/migrations/0043_merge_20260923_0819.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2.17 on 2026-09-23 08:19
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("app", "0042_app_deprecation_reason"),
+ ("app", "0042_merge_20260820_0919"),
+ ]
+
+ operations = []
diff --git a/saleor/app/models.py b/saleor/app/models.py
index a1bfbbf449..8c941cb47c 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -20,6 +20,9 @@ from .types import (
URL_MAX_LENGTH = 2048
"""Matches Django's ``URLValidator.max_length`` and the de facto browser cap."""
+DEPRECATION_REASON_MAX_LENGTH = 2048
+"""Matches ``AppProblem.message``, since the Dashboard renders both in the same UI."""
+
class AppQueryset(models.QuerySet["App"]):
def for_event_type(self, event_type: str):
@@ -77,6 +80,9 @@ class App(ModelWithMetadata):
audience = models.CharField(blank=True, null=True, max_length=256)
is_installed = models.BooleanField(default=True)
author = models.CharField(blank=True, null=True, max_length=60)
+ deprecation_reason = models.CharField(
+ max_length=DEPRECATION_REASON_MAX_LENGTH, blank=True, null=True
+ )
brand_logo_default = models.ImageField(
upload_to="app-brand-data", blank=True, null=True
)
diff --git a/saleor/app/tests/test_installation_utils.py b/saleor/app/tests/test_installation_utils.py
index 46ad008101..c61036fe3d 100644
--- a/saleor/app/tests/test_installation_utils.py
+++ b/saleor/app/tests/test_installation_utils.py
@@ -25,7 +25,7 @@ from ..installation_utils import (
install_app,
validate_app_install_response,
)
-from ..models import App
+from ..models import DEPRECATION_REASON_MAX_LENGTH, App
def test_validate_app_install_response():
@@ -1057,3 +1057,77 @@ def test_fetch_brand_data_task_saving_deleted_object(
mock_storage_delete.assert_called_once_with(
f"app-installation-brand-data/{file_name}"
)
+
+
+def test_install_app_with_deprecation_reason(
+ app_manifest, app_installation, monkeypatch
+):
+ # given
+ reason = "Replaced by the new payments app."
+ app_manifest["deprecationReason"] = reason
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert App.objects.get().id == app.id
+ assert app.deprecation_reason == reason
+
+
+def test_install_app_without_deprecation_reason(
+ app_manifest, app_installation, monkeypatch
+):
+ # given
+ assert "deprecationReason" not in app_manifest
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert app.deprecation_reason is None
+
+
[email protected]("blank_reason", ["", " "])
+def test_install_app_with_blank_deprecation_reason(
+ app_manifest, app_installation, monkeypatch, blank_reason
+):
+ # given
+ app_manifest["deprecationReason"] = blank_reason
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert app.deprecation_reason is None
+
+
+def test_install_app_with_too_long_deprecation_reason_does_not_fail_install(
+ app_manifest, app_installation, monkeypatch
+):
+ """An informational field must never be able to break an app install."""
+ # given
+ app_manifest["deprecationReason"] = "x" * (DEPRECATION_REASON_MAX_LENGTH + 100)
+ expected = "x" * (DEPRECATION_REASON_MAX_LENGTH - 1) + "…"
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert app.deprecation_reason == expected
+ assert len(app.deprecation_reason) == DEPRECATION_REASON_MAX_LENGTH
diff --git a/saleor/app/utils.py b/saleor/app/utils.py
index c8957285f7..ec689c1c34 100644
--- a/saleor/app/utils.py
+++ b/saleor/app/utils.py
@@ -1,5 +1,8 @@
+from django.utils.text import Truncator
+
from ..webhook.event_types import WebhookEventSyncType
from ..webhook.utils import get_webhooks_for_event
+from .models import DEPRECATION_REASON_MAX_LENGTH
def get_active_tax_apps(identifiers: list[str] | None = None):
@@ -16,3 +19,14 @@ def get_active_tax_apps(identifiers: list[str] | None = None):
order_apps = {webhook.app for webhook in order_webhooks}
return checkout_apps.union(order_apps)
+
+
+def normalize_deprecation_reason(value: str | None) -> str | None:
+ """Normalize an app's deprecation reason to what the column accepts.
+
+ Blank and whitespace-only values mean "not deprecated" and are stored as
+ NULL. Too long values are truncated rather than rejected: the reason is
+ purely informational, so it must never be able to fail an app install or a
+ mutation.
+ """
+ return Truncator((value or "").strip()).chars(DEPRECATION_REASON_MAX_LENGTH) or None
diff --git a/saleor/graphql/app/enums.py b/saleor/graphql/app/enums.py
index 0bb6cf8ca7..af119e829d 100644
--- a/saleor/graphql/app/enums.py
+++ b/saleor/graphql/app/enums.py
@@ -4,6 +4,7 @@ import graphene
from ...app import error_codes
from ...app.types import AppType
+from ..core.descriptions import ADDED_IN_323
from ..core.doc_category import DOC_CATEGORY_APPS
from ..core.enums import to_enum
@@ -86,3 +87,7 @@ AppProblemCreateErrorCode: Final[graphene.Enum] = graphene.Enum.from_enum(
AppProblemDismissErrorCode: Final[graphene.Enum] = graphene.Enum.from_enum(
error_codes.AppProblemDismissErrorCode
)
+AppSelfUpdateErrorCode: Final[graphene.Enum] = graphene.Enum.from_enum(
+ error_codes.AppSelfUpdateErrorCode,
+ description="Error codes for the appSelfUpdate mutation." + ADDED_IN_323,
+)
diff --git a/saleor/graphql/app/mutations/__init__.py b/saleor/graphql/app/mutations/__init__.py
index c2d7086b5e..3ad4deb803 100644
--- a/saleor/graphql/app/mutations/__init__.py
+++ b/saleor/graphql/app/mutations/__init__.py
@@ -9,6 +9,7 @@ from .app_problem_create import AppProblemCreate
from .app_problem_dismiss import AppProblemDismiss
from .app_reenable_sync_webhooks import AppReenableSyncWebhooks
from .app_retry_install import AppRetryInstall
+from .app_self_update import AppSelfUpdate
from .app_token_create import AppTokenCreate
from .app_token_delete import AppTokenDelete
from .app_token_verify import AppTokenVerify
@@ -25,6 +26,7 @@ __all__ = [
"AppFetchManifest",
"AppInstall",
"AppRetryInstall",
+ "AppSelfUpdate",
"AppTokenCreate",
"AppTokenDelete",
"AppTokenVerify",
diff --git a/saleor/graphql/app/mutations/app_fetch_manifest.py b/saleor/graphql/app/mutations/app_fetch_manifest.py
index 79974782bc..534948a472 100644
--- a/saleor/graphql/app/mutations/app_fetch_manifest.py
+++ b/saleor/graphql/app/mutations/app_fetch_manifest.py
@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError
from ....app.error_codes import AppErrorCode
from ....app.installation_utils import fetch_brand_data, fetch_manifest
from ....app.manifest_validations import clean_manifest_data, clean_manifest_url
+from ....app.utils import normalize_deprecation_reason
from ....permission.enums import AppPermission
from ...core import types as grapqhl_types
from ...core.doc_category import DOC_CATEGORY_APPS
@@ -84,6 +85,9 @@ class AppFetchManifest(BaseMutation):
audience=cleaned_data.get("audience"),
required_saleor_version=cleaned_data.get("requiredSaleorVersion"),
author=cleaned_data.get("author"),
+ deprecation_reason=normalize_deprecation_reason(
+ cleaned_data.get("deprecationReason")
+ ),
brand=cleaned_data.get("brand"),
)
diff --git a/saleor/graphql/app/mutations/app_self_update.py b/saleor/graphql/app/mutations/app_self_update.py
new file mode 100644
index 0000000000..f123843b75
--- /dev/null
+++ b/saleor/graphql/app/mutations/app_self_update.py
@@ -0,0 +1,83 @@
+from typing import Any, cast
+
+import graphene
+
+from ....app.models import DEPRECATION_REASON_MAX_LENGTH
+from ....app.models import App as AppModel
+from ....app.utils import normalize_deprecation_reason
+from ....permission.auth_filters import AuthorizationFilters
+from ...core import ResolveInfo
+from ...core.descriptions import ADDED_IN_323
+from ...core.doc_category import DOC_CATEGORY_APPS
+from ...core.mutations import BaseMutation
+from ...core.types import BaseInputObjectType, Error
+from ..enums import AppSelfUpdateErrorCode
+from ..types import App
+
+
+class AppSelfUpdateError(Error):
+ code = AppSelfUpdateErrorCode(
+ description="The error code." + ADDED_IN_323, required=True
+ )
+
+ class Meta:
+ description = "Represents errors in the appSelfUpdate mutation." + ADDED_IN_323
+ doc_category = DOC_CATEGORY_APPS
+
+
+class AppSelfUpdateInput(BaseInputObjectType):
+ deprecation_reason = graphene.String(
+ required=False,
+ description=(
+ "Reason why the app is deprecated. Setting it marks the app as "
+ "deprecated in the dashboard; the app itself keeps working as "
+ "usual. Pass a blank value to clear it. Omit the field or pass "
+ "`null` to leave it unchanged. Values longer than "
+ f"{DEPRECATION_REASON_MAX_LENGTH} characters are truncated." + ADDED_IN_323
+ ),
+ )
+
+ class Meta:
+ description = "Fields to update on the calling app." + ADDED_IN_323
+ doc_category = DOC_CATEGORY_APPS
+
+
+class AppSelfUpdate(BaseMutation):
+ app = graphene.Field(App, description="The updated app." + ADDED_IN_323)
+
+ class Arguments:
+ input = AppSelfUpdateInput(
+ required=True,
+ description="Fields to update on the calling app." + ADDED_IN_323,
+ )
+
+ class Meta:
+ description = (
+ "Updates the app that calls this mutation. Only the app itself can "
+ "change these fields - staff users cannot set them via `appUpdate`."
+ + ADDED_IN_323
+ )
+ doc_category = DOC_CATEGORY_APPS
+ permissions = (AuthorizationFilters.AUTHENTICATED_APP,)
+ error_type_class = AppSelfUpdateError
+
+ @classmethod
+ def perform_mutation(
+ cls, _root: None, info: ResolveInfo, /, **data: Any
+ ) -> "AppSelfUpdate":
+ app = cast(AppModel, info.context.app)
+ input_data = data["input"]
+
+ # `null` means "leave unchanged", exactly like omitting the field, so
+ # that fields added to this input later can't wipe each other - clients
+ # commonly serialize unset fields as explicit nulls. Clearing is done
+ # by sending a blank string, which `normalize_deprecation_reason` maps
+ # back to NULL.
+ reason_input = input_data.get("deprecation_reason")
+ if reason_input is not None:
+ reason = normalize_deprecation_reason(reason_input)
+ if reason != app.deprecation_reason:
+ app.deprecation_reason = reason
+ app.save(update_fields=["deprecation_reason"])
+
+ return AppSelfUpdate(app=app)
diff --git a/saleor/graphql/app/schema.py b/saleor/graphql/app/schema.py
index 5d1b83cfb4..f02ea50ef3 100644
--- a/saleor/graphql/app/schema.py
+++ b/saleor/graphql/app/schema.py
@@ -24,6 +24,7 @@ from .mutations import (
AppProblemDismiss,
AppReenableSyncWebhooks,
AppRetryInstall,
+ AppSelfUpdate,
AppTokenCreate,
AppTokenDelete,
AppTokenVerify,
@@ -196,4 +197,6 @@ class AppMutations(graphene.ObjectType):
app_problem_create = AppProblemCreate.Field()
app_problem_dismiss = AppProblemDismiss.Field()
+ app_self_update = AppSelfUpdate.Field()
+
app_reenable_sync_webhooks = AppReenableSyncWebhooks.Field()
diff --git a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
index 44158b1753..e0e5da4a21 100644
--- a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
+++ b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
@@ -9,7 +9,7 @@ from requests_hardened import HTTPSession
from ..... import schema_version
from .....app.error_codes import AppErrorCode
-from .....app.models import App
+from .....app.models import DEPRECATION_REASON_MAX_LENGTH, App
from .....thumbnail import IconThumbnailFormat
from ....tests.utils import assert_no_permission, get_graphql_content
@@ -1082,3 +1082,117 @@ def test_app_fetch_manifest_extension_with_invalid_absolute_url(
assert errors[0]["field"] == "extensions"
assert errors[0]["code"] == AppErrorCode.INVALID_URL_FORMAT.name
assert "url" in errors[0]["message"].lower()
+
+
+APP_FETCH_MANIFEST_DEPRECATION_MUTATION = """
+mutation AppFetchManifest($manifest_url: String!) {
+ appFetchManifest(manifestUrl: $manifest_url) {
+ manifest {
+ identifier
+ deprecationReason
+ }
+ errors {
+ field
+ code
+ message
+ }
+ }
+}
+"""
+
+
+def test_fetch_manifest_returns_deprecation_reason(
+ staff_api_client, app_manifest, permission_manage_apps, monkeypatch
+):
+ """Lets the dashboard warn about a deprecated app before it is installed."""
+ # given
+ reason = "Replaced by the new payments app."
+ app_manifest["deprecationReason"] = reason
+ manifest_url = "http://localhost:3000/manifest"
+ mocked_response = Mock()
+ mocked_response.status_code = 200
+ mocked_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_response))
+ variables = {"manifest_url": manifest_url}
+
+ # when
+ response = staff_api_client.post_graphql(
+ APP_FETCH_MANIFEST_DEPRECATION_MUTATION,
+ variables=variables,
+ permissions=(permission_manage_apps,),
+ )
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appFetchManifest"]
+ assert len(data["errors"]) == 0
+ assert data["manifest"]["deprecationReason"] == reason
+
+
+def test_fetch_manifest_without_deprecation_reason(
+ staff_api_client, app_manifest, permission_manage_apps, monkeypatch
+):
+ # given
+ assert "deprecationReason" not in app_manifest
+ manifest_url = "http://localhost:3000/manifest"
+ mocked_response = Mock()
+ mocked_response.status_code = 200
+ mocked_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_response))
+ variables = {"manifest_url": manifest_url}
+
+ # when
+ response = staff_api_client.post_graphql(
+ APP_FETCH_MANIFEST_DEPRECATION_MUTATION,
+ variables=variables,
+ permissions=(permission_manage_apps,),
+ )
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appFetchManifest"]
+ assert len(data["errors"]) == 0
+ assert data["manifest"]["deprecationReason"] is None
+
+
+ ("manifest_reason", "expected_reason"),
+ [
+ ("", None),
+ (" ", None),
+ (" Replaced by the new payments app. ", "Replaced by the new payments app."),
+ (
+ "x" * (DEPRECATION_REASON_MAX_LENGTH + 100),
+ "x" * (DEPRECATION_REASON_MAX_LENGTH - 1) + "…",
+ ),
+ ],
+)
+def test_fetch_manifest_normalizes_deprecation_reason(
+ staff_api_client,
+ app_manifest,
+ permission_manage_apps,
+ monkeypatch,
+ manifest_reason,
+ expected_reason,
+):
+ # given
+ app_manifest["deprecationReason"] = manifest_reason
+ manifest_url = "http://localhost:3000/manifest"
+ mocked_response = Mock()
+ mocked_response.status_code = 200
+ mocked_response.json.return_value = app_manifest
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_response))
+ variables = {"manifest_url": manifest_url}
+
+ # when
+ response = staff_api_client.post_graphql(
+ APP_FETCH_MANIFEST_DEPRECATION_MUTATION,
+ variables=variables,
+ permissions=(permission_manage_apps,),
+ )
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appFetchManifest"]
+ assert len(data["errors"]) == 0
+ assert data["manifest"]["deprecationReason"] == expected_reason
diff --git a/saleor/graphql/app/tests/mutations/test_app_self_update.py b/saleor/graphql/app/tests/mutations/test_app_self_update.py
new file mode 100644
index 0000000000..b6f1656d0a
--- /dev/null
+++ b/saleor/graphql/app/tests/mutations/test_app_self_update.py
@@ -0,0 +1,183 @@
+from unittest import mock
+
+import pytest
+
+from .....app.models import DEPRECATION_REASON_MAX_LENGTH
+from ....tests.utils import assert_no_permission, get_graphql_content
+
+APP_SELF_UPDATE_MUTATION = """
+ mutation AppSelfUpdate($input: AppSelfUpdateInput!) {
+ appSelfUpdate(input: $input) {
+ app {
+ id
+ deprecationReason
+ }
+ errors {
+ field
+ code
+ message
+ }
+ }
+ }
+"""
+
+
+def test_sets_deprecation_reason(app_api_client, app):
+ # given
+ reason = "Replaced by the new payments app."
+ assert app.deprecation_reason is None
+ variables = {"input": {"deprecationReason": reason}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] == reason
+
+ app.refresh_from_db(fields=("deprecation_reason",))
+ assert app.deprecation_reason == reason
+
+
[email protected]("blank_value", ["", " "])
+def test_blank_value_clears_deprecation_reason(app_api_client, app, blank_value):
+ # given
+ app.deprecation_reason = "Sunsetting in January."
+ app.save(update_fields=["deprecation_reason"])
+ variables = {"input": {"deprecationReason": blank_value}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] is None
+
+ app.refresh_from_db(fields=("deprecation_reason",))
+ assert app.deprecation_reason is None
+
+
[email protected]("input_data", [{}, {"deprecationReason": None}])
+def test_omitted_or_null_leaves_deprecation_reason_untouched(
+ app_api_client, app, input_data
+):
+ """Guards the contract that future fields on this input won't wipe each other.
+
+ Explicit `null` must behave like omitting the field, because clients
+ commonly serialize unset fields as nulls. Only a blank string clears.
+ """
+ # given
+ reason = "Sunsetting in January."
+ app.deprecation_reason = reason
+ app.save(update_fields=["deprecation_reason"])
+ variables = {"input": input_data}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] == reason
+
+ app.refresh_from_db(fields=("deprecation_reason",))
+ assert app.deprecation_reason == reason
+
+
+def test_too_long_deprecation_reason_is_truncated_not_rejected(app_api_client, app):
+ # given
+ reason = "x" * (DEPRECATION_REASON_MAX_LENGTH + 100)
+ expected = "x" * (DEPRECATION_REASON_MAX_LENGTH - 1) + "…"
+ variables = {"input": {"deprecationReason": reason}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] == expected
+
+ app.refresh_from_db(fields=("deprecation_reason",))
+ assert app.deprecation_reason == expected
+ assert len(app.deprecation_reason) == DEPRECATION_REASON_MAX_LENGTH
+
+
+def test_value_at_max_length_is_stored_verbatim(app_api_client, app):
+ # given
+ reason = "x" * DEPRECATION_REASON_MAX_LENGTH
+ variables = {"input": {"deprecationReason": reason}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] == reason
+
+
+def test_value_is_stripped(app_api_client, app):
+ # given
+ reason = "Replaced by the new payments app."
+ variables = {"input": {"deprecationReason": f" {reason} "}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["appSelfUpdate"]
+ assert len(data["errors"]) == 0
+ assert data["app"]["deprecationReason"] == reason
+
+
[email protected]("saleor.plugins.manager.PluginsManager.app_updated")
+def test_does_not_fire_app_updated_webhook(mocked_app_updated, app_api_client, app):
+ """App lifecycle events are self-only, so the app would only notify itself."""
+ # given
+ variables = {"input": {"deprecationReason": "Replaced by the new payments app."}}
+
+ # when
+ response = app_api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ # then
+ assert len(content["data"]["appSelfUpdate"]["errors"]) == 0
+ assert mocked_app_updated.call_count == 0
+
+
+ "api_client_fixture",
+ ["staff_api_client", "superuser_api_client", "user_api_client", "api_client"],
+)
+def test_no_user_can_set_deprecation_reason(
+ request, api_client_fixture, app, permission_manage_apps
+):
+ """Only the app itself may deprecate itself.
+
+ No requestor that is not an app can do it - not staff (even holding
+ MANAGE_APPS), not a superuser, not a customer, not an anonymous caller.
+ `appUpdate` has no such field either.
+ """
+ # given
+ assert app.deprecation_reason is None
+ api_client = request.getfixturevalue(api_client_fixture)
+ if api_client.user:
+ api_client.user.user_permissions.add(permission_manage_apps)
+ variables = {"input": {"deprecationReason": "Deprecated by a user."}}
+
+ # when
+ response = api_client.post_graphql(APP_SELF_UPDATE_MUTATION, variables)
+
+ # then
+ assert_no_permission(response)
+ app.refresh_from_db(fields=("deprecation_reason",))
+ assert app.deprecation_reason is None
diff --git a/saleor/graphql/app/tests/queries/test_app.py b/saleor/graphql/app/tests/queries/test_app.py
index aceb16f598..5d36a149fc 100644
--- a/saleor/graphql/app/tests/queries/test_app.py
+++ b/saleor/graphql/app/tests/queries/test_app.py
@@ -809,3 +809,53 @@ def test_app_query_breaker_last_change(
content["data"]["app"]["breakerLastStateChange"]
)
assert retrieved_date == now
+
+
+QUERY_APP_DEPRECATION_REASON = """
+ query ($id: ID) {
+ app(id: $id) {
+ id
+ deprecationReason
+ }
+ }
+"""
+
+
+def test_app_deprecation_reason(app, staff_api_client, permission_manage_apps):
+ # given
+ reason = "Replaced by the new payments app."
+ app.deprecation_reason = reason
+ app.save(update_fields=["deprecation_reason"])
+ variables = {"id": graphene.Node.to_global_id("App", app.id)}
+
+ # when
+ response = staff_api_client.post_graphql(
+ QUERY_APP_DEPRECATION_REASON,
+ variables,
+ permissions=(permission_manage_apps,),
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ # then
+ assert content["data"]["app"]["deprecationReason"] == reason
+
+
+def test_app_deprecation_reason_null_when_not_deprecated(
+ app, staff_api_client, permission_manage_apps
+):
+ # given
+ assert app.deprecation_reason is None
+ variables = {"id": graphene.Node.to_global_id("App", app.id)}
+
+ # when
+ response = staff_api_client.post_graphql(
+ QUERY_APP_DEPRECATION_REASON,
+ variables,
+ permissions=(permission_manage_apps,),
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ # then
+ assert content["data"]["app"]["deprecationReason"] is None
diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.py
index 8168f4e844..216f17de76 100644
--- a/saleor/graphql/app/types.py
+++ b/saleor/graphql/app/types.py
@@ -478,6 +478,15 @@ class Manifest(BaseObjectType):
deprecation_reason="Use `dataPrivacyUrl` instead.",
)
data_privacy_url = graphene.String(description="URL to the full privacy policy.")
+ deprecation_reason = graphene.String(
+ description=(
+ "Reason why the app is deprecated, declared in the manifest. "
+ "Null when the app is not deprecated. A deprecated app can still "
+ "be installed and works as usual, but usually means it should not "
+ "be used anymore." + ADDED_IN_323
+ ),
+ required=False,
+ )
homepage_url = graphene.String(description="External URL to the app homepage.")
support_url = graphene.String(
description="External URL to the page where app users can find support."
@@ -704,6 +713,15 @@ class App(ModelObjectType[models.App]):
description="JWT token used to authenticate by third-party app."
)
author = graphene.String(description="The App's author name.")
+ deprecation_reason = graphene.String(
+ description=(
+ "Reason why the app is deprecated, set by the app itself. "
+ "Null when the app is not deprecated. A deprecated app keeps "
+ "working as usual, but usually means it should not be used "
+ "anymore." + ADDED_IN_323
+ ),
+ required=False,
+ )
extensions = NonNullList(
AppExtension,
description="App's dashboard extensions.",
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 3e91d1995b..424fb8e867 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -3000,6 +3000,13 @@ type App implements Node & ObjectWithMetadata @doc(category: "Apps") {
"""The App's author name."""
author: String
+ """
+ Reason why the app is deprecated, set by the app itself. Null when the app is not deprecated. A deprecated app keeps working as usual, but usually means it should not be used anymore.
+
+ Added in Saleor 3.23.
+ """
+ deprecationReason: String
+
"""App's dashboard extensions."""
extensions: [AppExtension!]!
@@ -21846,6 +21853,22 @@ type Mutation {
input: AppProblemDismissInput!
): AppProblemDismiss @doc(category: "Apps")
+ """
+ Updates the app that calls this mutation. Only the app itself can change these fields - staff users cannot set them via `appUpdate`.
+
+ Added in Saleor 3.23.
+
+ Requires one of the following permissions: AUTHENTICATED_APP.
+ """
+ appSelfUpdate(
+ """
+ Fields to update on the calling app.
+
+ Added in Saleor 3.23.
+ """
+ input: AppSelfUpdateInput!
+ ): AppSelfUpdate @doc(category: "Apps")
+
"""
Re-enable sync webhooks for provided app. Can be used to manually re-enable sync webhooks for the app before the cooldown period ends.
@@ -32587,6 +32610,13 @@ type Manifest @doc(category: "Apps") {
"""URL to the full privacy policy."""
dataPrivacyUrl: String
+ """
+ Reason why the app is deprecated, declared in the manifest. Null when the app is not deprecated. A deprecated app can still be installed and works as usual, but usually means it should not be used anymore.
+
+ Added in Saleor 3.23.
+ """
+ deprecationReason: String
+
"""External URL to the app homepage."""
homepageUrl: String
@@ -32851,6 +32881,70 @@ input AppProblemDismissByStaffWithKeysInput @doc(category: "Apps") {
app: ID!
}
+"""
+Updates the app that calls this mutation. Only the app itself can change these fields - staff users cannot set them via `appUpdate`.
+
+Added in Saleor 3.23.
+
+Requires one of the following permissions: AUTHENTICATED_APP.
+"""
+type AppSelfUpdate @doc(category: "Apps") {
+ """
+ The updated app.
+
+ Added in Saleor 3.23.
+ """
+ app: App
+ errors: [AppSelfUpdateError!]!
+}
+
+"""
+Represents errors in the appSelfUpdate mutation.
+
+Added in Saleor 3.23.
+"""
+type AppSelfUpdateError @doc(category: "Apps") {
+ """
+ Name of a field that caused the error. A value of `null` indicates that the error isn't associated with a particular field.
+ """
+ field: String
+
+ """The error message."""
+ message: String
+
+ """
+ The error code.
+
+ Added in Saleor 3.23.
+ """
+ code: AppSelfUpdateErrorCode!
+}
+
+"""
+Error codes for the appSelfUpdate mutation.
+
+Added in Saleor 3.23.
+"""
+enum AppSelfUpdateErrorCode {
+ GRAPHQL_ERROR
+ INVALID
+ REQUIRED
+}
+
+"""
+Fields to update on the calling app.
+
+Added in Saleor 3.23.
+"""
+input AppSelfUpdateInput @doc(category: "Apps") {
+ """
+ Reason why the app is deprecated. Setting it marks the app as deprecated in the dashboard; the app itself keeps working as usual. Pass a blank value to clear it. Omit the field or pass `null` to leave it unchanged. Values longer than 2048 characters are truncated.
+
+ Added in Saleor 3.23.
+ """
+ deprecationReason: String
+}
+
"""
Re-enable sync webhooks for provided app. Can be used to manually re-enable sync webhooks for the app before the cooldown period ends.