diff --git a/metaflow/plugins/events_decorator.py b/metaflow/plugins/events_decorator.py index 2d13096aa4a..cc29b5c2234 100644 --- a/metaflow/plugins/events_decorator.py +++ b/metaflow/plugins/events_decorator.py @@ -422,7 +422,9 @@ def flow_init( ) if "project_branch" in self.attributes["flow"]: if is_stringish(self.attributes["flow"]["project_branch"]): - result["branch"] = self.attributes["flow"]["project_branch"] + result["project_branch"] = self.attributes["flow"][ + "project_branch" + ] else: raise MetaflowException( "The *project_branch* attribute of the *flow* is not a string" @@ -467,6 +469,7 @@ def flow_init( "The *name* attribute '%s' is not a valid string" % str(flow_name) ) + result = {"fq_name": flow_name} if "project" in flow: if is_stringish(flow["project"]): @@ -478,7 +481,7 @@ def flow_init( ) if "project_branch" in flow: if is_stringish(flow["project_branch"]): - result["branch"] = flow["project_branch"] + result["project_branch"] = flow["project_branch"] else: raise MetaflowException( "The *project_branch* attribute of the *flow* %s " @@ -597,9 +600,41 @@ def format_deploytime_value(self): # Entire trigger is a function (returns either string or dict) old_trig = trigger if isinstance(trigger, DeployTimeField): + # convert the trigger to string or dict trigger = deploy_time_eval(trigger) + if is_stringish(trigger): + pass + elif isinstance(trigger, dict): + if "name" not in trigger: + raise MetaflowException( + "The *flow* attribute for *@trigger_on_finish* is missing the " + "*name* key." + ) + flow_name = trigger["name"] + + if not is_stringish(flow_name) or "." in flow_name: + raise MetaflowException( + "The *name* attribute of the *flow* is not a valid string" + ) + result = {"fq_name": flow_name} + if "project" in trigger: + if is_stringish(trigger["project"]): + result["project"] = trigger["project"] + else: + raise MetaflowException( + "The *project* attribute of the *flow* is not a string" + ) + if "project_branch" in trigger: + if is_stringish(trigger["project_branch"]): + result["project_branch"] = trigger["project_branch"] + else: + raise MetaflowException( + "The *project_branch* attribute of the *flow* is not a string" + ) + trigger = result + # effect is to set all fields to None if they don't exist. if isinstance(trigger, dict): - trigger["fq_name"] = trigger.get("name") + trigger["fq_name"] = trigger.get("fq_name") trigger["project"] = trigger.get("project") trigger["branch"] = trigger.get("project_branch") # We also added this bc it won't be formatted yet