Skip to content

Commit

Permalink
remove json.loads and add tuple to param type
Browse files Browse the repository at this point in the history
  • Loading branch information
KaylaSeeley committed Nov 14, 2024
1 parent 0f1effa commit d7211ef
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions metaflow/plugins/events_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def flow_init(
parameters, DeployTimeField
):
new_param_value = DeployTimeField(
"parameters", [list, dict], None, parameters, False
"parameters", [list, dict, tuple], None, parameters, False
)
self.attributes["event"]["parameters"] = new_param_value
self.triggers.append(self.attributes["event"])
Expand Down Expand Up @@ -193,7 +193,7 @@ def flow_init(
parameters, DeployTimeField
):
new_param_value = DeployTimeField(
"parameters", [list, dict], None, parameters, False
"parameters", [list, dict, tuple], None, parameters, False
)
event["parameters"] = new_param_value
self.triggers.append(event)
Expand Down Expand Up @@ -266,16 +266,11 @@ def format_deploytime_value(self):

self.triggers = new_triggers
for trigger in self.triggers:
print(trigger)
old_trigger = trigger
trigger_params = trigger.get("parameters", {})
# Case where param is a function (can return list or dict)
if isinstance(trigger_params, DeployTimeField):
trigger_params = deploy_time_eval(trigger_params)
try:
trigger_params = json.loads(trigger_params)
except (TypeError, json.JSONDecodeError):
pass
# If params is a list of strings, convert to dict with same key and value
if isinstance(trigger_params, (list, tuple)):
new_trigger_params = {}
Expand All @@ -290,7 +285,6 @@ def format_deploytime_value(self):
"It should be a list/tuple of strings and lists/tuples "
"of size 2" % self.attributes["event"]["name"]
)

trigger_params = new_trigger_params
trigger["parameters"] = trigger_params

Expand Down Expand Up @@ -597,10 +591,6 @@ def format_deploytime_value(self):
old_trig = trigger
if isinstance(trigger, DeployTimeField):
trigger = deploy_time_eval(trigger)
try:
trigger = json.loads(trigger)
except (TypeError, json.JSONDecodeError):
pass
if isinstance(trigger, dict):
trigger["fq_name"] = trigger.get("name")
trigger["project"] = trigger.get("project")
Expand Down

0 comments on commit d7211ef

Please sign in to comment.