Skip to content

Refactor trigger decorator and deploy time evaluation logic #2290

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

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

Conversation

talsperre
Copy link
Collaborator

@talsperre talsperre commented Feb 22, 2025

Refactored @trigger logic and simplified the deploy time evaluation logic of @trigger decorator. The current implementation is buggy and fails when running trigger4.py in this gist here.

For testing, refer to all the flows in this gist here. We can add few more tests as well if needed.

Change in contract:

Previously, we allowed deploy time functions (not documented anywhere) at various levels in the @trigger decorator. So something like this was possible:

@trigger(
    events=[
        {
            "name": myfunc1,
            "parameters": [myfunc2, myfunc3]
        },
)
class MyFlow(FlowSpec):

Now, we only allow specifying all of parameters as a deploy time function:

@trigger(
    events=[
        {
            "name": myfunc1,
            "parameters": myfunc2
        },
)
class MyFlow(FlowSpec):

These are also still allowed:

@trigger(events=myfunc)
class MyFlow(FlowSpec):
@trigger(events=[myfunc1, myfunc2])
class MyFlow(FlowSpec):

@nflx-mf-bot
Copy link
Collaborator

Netflix internal testing[4457218] @ 3b7ef8e

@nflx-mf-bot
Copy link
Collaborator

Testing for OSS PR [1052] @ commit 3b7ef8e had 11 FAILUREs.

@talsperre talsperre force-pushed the dev/trigger-refactor branch from 3b7ef8e to 05e0587 Compare June 25, 2025 01:09
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.

A few minor comments. I haven't tested with the test flows yet but will look.

param_name, field_name = mapping
if not is_stringish(param_name) or not is_stringish(field_name):
raise MetaflowException(
f"The *parameters* attribute for event {event_name} is invalid. "
Copy link
Contributor

Choose a reason for hiding this comment

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

this error message does not seem to properly reflect the condition here. You are actually checking the the content of the tuple are also strings. That too, this is a list of strings or tuples.

elif isinstance(parameters, dict):
# {Union[func, param_name]: Union[func, param_name]}
Copy link
Contributor

Choose a reason for hiding this comment

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

This also seems like a wrong comment based on the error condition below.


Returns
-------
Union[Dict[Union[str, callable], Union[str, callable]], Callable]
Copy link
Contributor

Choose a reason for hiding this comment

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

return type seems too permissive. You are either returning a callable or a Dict[str, str]

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

Successfully merging this pull request may close these issues.

4 participants