Skip to content

Commit c78c202

Browse files
talsperrekayla seeleyKaylaSeeleysaikonenromain-intel
authored
Deploy time triggers (v2) (Netflix#2157)
* trigger_on_finish sorta works * trigger deco works for event * trigger events changes * run black * ok this one ran black * black ran for real * deleting some things i missed * add format_deploytime_value() to both decos * fixes error with types * ran black * fixes failing cases * remove json.loads and add tuple to param type * ran black * function within parameter * Delete local config file * fixing borked cases * refactor code * shouldn't be changes to flowspec.py * fixing bugs * add deploy time trigger inits to argo parameter handling (Netflix#2146) * run black * undo modifications to to_pod * reset util file * pr comment * remove print * remove bad append * Fix issue with to_pod and deploy time fields --------- Co-authored-by: kayla seeley <[email protected]> Co-authored-by: KaylaSeeley <[email protected]> Co-authored-by: KaylaSeeley <[email protected]> Co-authored-by: Sakari Ikonen <[email protected]> Co-authored-by: Romain Cledat <[email protected]>
1 parent c7cb8b5 commit c78c202

File tree

4 files changed

+274
-78
lines changed

4 files changed

+274
-78
lines changed

metaflow/parameters.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,28 @@ def __call__(self, deploy_time=False):
151151
return self._check_type(val, deploy_time)
152152

153153
def _check_type(self, val, deploy_time):
154+
154155
# it is easy to introduce a deploy-time function that accidentally
155156
# returns a value whose type is not compatible with what is defined
156157
# in Parameter. Let's catch those mistakes early here, instead of
157158
# showing a cryptic stack trace later.
158159

159160
# note: this doesn't work with long in Python2 or types defined as
160161
# click types, e.g. click.INT
161-
TYPES = {bool: "bool", int: "int", float: "float", list: "list"}
162+
TYPES = {bool: "bool", int: "int", float: "float", list: "list", dict: "dict"}
162163

163164
msg = (
164165
"The value returned by the deploy-time function for "
165166
"the parameter *%s* field *%s* has a wrong type. "
166167
% (self.parameter_name, self.field)
167168
)
168169

169-
if self.parameter_type in TYPES:
170+
if isinstance(self.parameter_type, list):
171+
if not any(isinstance(val, x) for x in self.parameter_type):
172+
msg += "Expected one of the following %s." % TYPES[self.parameter_type]
173+
raise ParameterFieldTypeMismatch(msg)
174+
return str(val) if self.return_str else val
175+
elif self.parameter_type in TYPES:
170176
if type(val) != self.parameter_type:
171177
msg += "Expected a %s." % TYPES[self.parameter_type]
172178
raise ParameterFieldTypeMismatch(msg)

metaflow/plugins/argo/argo_workflows.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ def _process_triggers(self):
522522
params = set(
523523
[param.name.lower() for var, param in self.flow._get_parameters()]
524524
)
525-
for event in self.flow._flow_decorators.get("trigger")[0].triggers:
525+
trigger_deco = self.flow._flow_decorators.get("trigger")[0]
526+
trigger_deco.format_deploytime_value()
527+
for event in trigger_deco.triggers:
526528
parameters = {}
527529
# TODO: Add a check to guard against names starting with numerals(?)
528530
if not re.match(r"^[A-Za-z0-9_.-]+$", event["name"]):
@@ -562,9 +564,11 @@ def _process_triggers(self):
562564

563565
# @trigger_on_finish decorator
564566
if self.flow._flow_decorators.get("trigger_on_finish"):
565-
for event in self.flow._flow_decorators.get("trigger_on_finish")[
566-
0
567-
].triggers:
567+
trigger_on_finish_deco = self.flow._flow_decorators.get(
568+
"trigger_on_finish"
569+
)[0]
570+
trigger_on_finish_deco.format_deploytime_value()
571+
for event in trigger_on_finish_deco.triggers:
568572
# Actual filters are deduced here since we don't have access to
569573
# the current object in the @trigger_on_finish decorator.
570574
triggers.append(

0 commit comments

Comments
 (0)