Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Allow string as exceptions in `on_failure_callback` (#695)

Madison Swain-Bowden25feeb73cbda
diff --git a/openverse_catalog/dags/common/slack.py b/openverse_catalog/dags/common/slack.py
index ec6179607..122fb3503 100644
--- a/openverse_catalog/dags/common/slack.py
+++ b/openverse_catalog/dags/common/slack.py
@@ -308,7 +308,10 @@ def on_failure_callback(context: dict) -> None:
if exception:
# Forgo the alert on upstream failures
- if "Upstream task(s) failed" in exception.args:
+ if (
+ isinstance(exception, Exception)
+ and "Upstream task(s) failed" in exception.args
+ ):
log.info("Forgoing Slack alert due to upstream failures")
return
exception_message = f"""
diff --git a/tests/dags/common/test_slack.py b/tests/dags/common/test_slack.py
index b9bf7f675..00fff3290 100644
--- a/tests/dags/common/test_slack.py
+++ b/tests/dags/common/test_slack.py
@@ -403,6 +403,11 @@ def test_send_alert_skips_when_silenced(silenced_errors, alert, should_send):
(ValueError("Whoops!"), "dev", True, True),
(ValueError("Whoops!"), "prod", False, True),
(ValueError("Whoops!"), "prod", True, True),
+ # Strings should also be allowed
+ ("task marked as failed externally", "dev", False, False),
+ ("task marked as failed externally", "dev", True, True),
+ ("task marked as failed externally", "prod", False, True),
+ ("task marked as failed externally", "prod", True, True),
# Message without exception
(None, "dev", False, False),
(None, "dev", True, True),