From e1ae62c72f97e5234dcb4f7fd361719a8f621b71 Mon Sep 17 00:00:00 2001 From: Sakari Ikonen <64256562+saikonen@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:33:16 +0200 Subject: [PATCH] fix: Argo events project bug (#2216) * fix project_branch handling * add validation to argo events for incomplete project info in event spec --- metaflow/plugins/argo/argo_workflows.py | 20 ++++++++++++++------ metaflow/plugins/events_decorator.py | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/metaflow/plugins/argo/argo_workflows.py b/metaflow/plugins/argo/argo_workflows.py index 6fc1b57c80..5cdf07c67a 100644 --- a/metaflow/plugins/argo/argo_workflows.py +++ b/metaflow/plugins/argo/argo_workflows.py @@ -624,6 +624,16 @@ def _process_triggers(self): for event in trigger_on_finish_deco.triggers: # Actual filters are deduced here since we don't have access to # the current object in the @trigger_on_finish decorator. + project_name = event.get("project") or current.get("project_name") + branch_name = event.get("branch") or current.get("branch_name") + # validate that we have complete project info for an event name + if project_name or branch_name: + if not (project_name and branch_name): + # if one of the two is missing, we would end up listening to an event that will never be broadcast. + raise ArgoWorkflowsException( + "Incomplete project info. Please specify both 'project' and 'project_branch' or use the @project decorator" + ) + triggers.append( { # Make sure this remains consistent with the event name format @@ -632,18 +642,16 @@ def _process_triggers(self): % ".".join( v for v in [ - event.get("project") or current.get("project_name"), - event.get("branch") or current.get("branch_name"), + project_name, + branch_name, event["flow"], ] if v ), "filters": { "auto-generated-by-metaflow": True, - "project_name": event.get("project") - or current.get("project_name"), - "branch_name": event.get("branch") - or current.get("branch_name"), + "project_name": project_name, + "branch_name": branch_name, # TODO: Add a time filters to guard against cached events }, "type": "run", diff --git a/metaflow/plugins/events_decorator.py b/metaflow/plugins/events_decorator.py index 120f29f73c..5fba693e45 100644 --- a/metaflow/plugins/events_decorator.py +++ b/metaflow/plugins/events_decorator.py @@ -635,7 +635,7 @@ def format_deploytime_value(self): if isinstance(trigger, dict): trigger["fq_name"] = trigger.get("name") trigger["project"] = trigger.get("project") - trigger["branch"] = trigger.get("project_branch") + trigger["branch"] = trigger.get("branch") # We also added this bc it won't be formatted yet if isinstance(trigger, str): trigger = {"fq_name": trigger}