khuyentran1401 / prefect-alert

A decorator that sends alert when a Prefect flow fails
https://khuyentran1401.github.io/prefect-alert/
Apache License 2.0
13 stars 3 forks source link

Can't build a flow deployment when this decorator is used #1

Closed david-elliott-deliveroo closed 2 years ago

david-elliott-deliveroo commented 2 years ago

Absolutely LOVE this mechanism (wrapping a flow to add further custom flow handling) so thank you!! But, I can't get the flow deployment build to run (despite a lot of trying with a custom version of this decorator).

I'm getting the error Found object of unexpected type 'function'. Expected 'Flow'. when running prefect deployment build workflows/demo_8.py:failed_flow -n test-basic -q test-queue

Basically it appears that by adding the @alert_on_failure() decorator, that's then returning an object of type function rather than of type Flow which is then breaking something in deployment build..? I've tried cast'ing the output back to flow with little success. Please help!

Was tested using prefect==2.6.1 and prefect-alert==0.1.1 and with the exact flow from the readme.

khuyentran1401 commented 2 years ago

Hi @david-elliott-deliveroo, thanks for raising the issue. Hmm that makes sense. I'll see if I can some up with any solution to this

ahuang11 commented 2 years ago

In deployment.py:

        flow = prefect.utilities.importtools.import_object(entrypoint)
        if isinstance(flow, Flow):
            app.console.print(f"Found flow {flow.name!r}", style="green")
        else:
            exit_with_error(
                f"Found object of unexpected type {type(flow).__name__!r}. Expected 'Flow'."
            )

This might need to be loosened up; searching for the flow

    while hasattr(flow, "__wrapped__"):
        if isinstance(flow, Flow):
            break
        flow = flow.__wrapped__

Not sure if this will break anything else though

khuyentran1401 commented 2 years ago

Since making this possible requires a change in the Prefect code base, this issue is mentioned at https://github.com/PrefectHQ/prefect/issues/7338.