Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy time triggers #2133

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Deploy time triggers #2133

wants to merge 14 commits into from

Conversation

Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't fully finished the main function but I think it needs a bit more work (and some structure to reason about). It is a bit convoluted (not the function, just the logic) so we need to be careful and think clearly (ie: write things out :) ).

metaflow/parameters.py Outdated Show resolved Hide resolved
@@ -312,6 +422,13 @@ def flow_init(
"The *project_branch* attribute of the *flow* is not a string"
)
self.triggers.append(result)
elif callable(self.attributes["flow"]) and not isinstance(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here and other similar place: we probably want to also allow DeployTimeField (ie: not raise incorrect type). I don't think it happens but in terms of logic, we are ok with a deploytimefield.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this check in our old trigger code in metaflow-custom, so I kept it

if isinstance(value, (str, int, float)):
return value
if isinstance(value, dict):
return {to_pod(k): to_pod(v) for k, v in value.items()}
if isinstance(value, (list, set, tuple)):
return [to_pod(v) for v in value]
if isinstance(value, DeployTimeField):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this happen? I am not a fan of double "deploy time eval" since technically that can result in different values thereby giving an incorrect information to the user.

param_value, DeployTimeField
):
new_param_value = DeployTimeField(
"param", [list, dict], None, param_value, False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd call it "parameters" as well here since that is what the user is passing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems parameters can be a tuple or a list or a dict (here you just added list and dict).

We do lose the check on tuple of size 2 here but maybe we get it back later.

metaflow/plugins/events_decorator.py Outdated Show resolved Hide resolved
metaflow/plugins/events_decorator.py Outdated Show resolved Hide resolved
metaflow/plugins/events_decorator.py Outdated Show resolved Hide resolved
# Case were trigger is a function that returns a list of events
# Need to do this bc we need to iterate over list later
if isinstance(trigger, DeployTimeField):
if isinstance(deploy_time_eval(trigger), list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling deploy_time_eval twice. Also, at the top level, something that is a deploy-time field will be:

  • a string (so needs to be handled like line 96)
  • a dictionary (single event in dict form)
  • a list of the two things above (when it is pushed as events)

So for string, that is done (we create the proper entry and done). For dictionary, we may need further processing of the elements (so continue). For list, add each element as above.

for trigger in self.triggers:
old_trigger = trigger
# Entire event is a function (returns either string or dict)
if isinstance(trigger, DeployTimeField):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not happen since we removed the DeployTimeField in the first step. Now we need to go inside each dict (we either have a fully resolved dict or a dict with some portions that are not yet evaluated).

if isinstance(trigger_params, DeployTimeField):
trigger_params = deploy_time_eval(trigger_params)
try:
trigger_params = json.loads(trigger_params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need this -- the user needs to return this appropriately.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this happens when the user returns a dictionary, not sure why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants