Skip to content

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

Handle a celery task error when the job_id is missing in the db

Ania Warzechad0ed5276e5df
diff --git a/saleor/app/tasks.py b/saleor/app/tasks.py
index cf591fbb26..77b56c27fe 100644
--- a/saleor/app/tasks.py
+++ b/saleor/app/tasks.py
@@ -18,7 +18,13 @@ logger = logging.getLogger(__name__)
@celeryconf.app.task
def install_app_task(job_id, activate=False):
- app_installation = AppInstallation.objects.get(id=job_id)
+ try:
+ app_installation = AppInstallation.objects.get(id=job_id)
+ except AppInstallation.DoesNotExist:
+ logger.warning(
+ "Failed to install app. AppInstallation not found for job_id: %s.", job_id
+ )
+ return
try:
app, _ = install_app(app_installation, activate=activate)
app_installation.delete()
diff --git a/saleor/app/tests/test_app_tasks.py b/saleor/app/tests/test_app_tasks.py
index 1cb8e36297..3a3352b2fc 100644
--- a/saleor/app/tests/test_app_tasks.py
+++ b/saleor/app/tests/test_app_tasks.py
@@ -23,6 +23,16 @@ def test_install_app_task(app_installation):
assert app.is_installed
+def test_install_app_task_job_id_does_not_exist():
+ # given & when
+ nonexistent_job_id = 5435435345
+ install_app_task(nonexistent_job_id, activate=True)
+
+ # then
+ assert not App.objects.exists()
+
+
@pytest.mark.vcr
def test_install_app_task_wrong_format_of_target_token_url():
app_installation = AppInstallation.objects.create(