khuyentran1401 / prefect-alert

A decorator that sends alert when a Prefect flow fails

Home Page:https://khuyentran1401.github.io/prefect-alert/

Repository from Github https://github.comkhuyentran1401/prefect-alertRepository from Github https://github.comkhuyentran1401/prefect-alert

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

david-elliott-deliveroo opened this issue · comments

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.

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

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

Since making this possible requires a change in the Prefect code base, this issue is mentioned at PrefectHQ/prefect#7338.