https://flyte.org logo
#ask-the-community
Title
# ask-the-community
e

Endre Karlson

02/12/2024, 3:58 PM
When doing a query for a report we have some time that we get psycopg2.errors.DivisionByZero error and then I try to try / except it but it seems the error is still caught be Flyte and propagated up ?
s

Samhita Alla

02/12/2024, 4:52 PM
hi @Endre Karlson! are you using eager workflows?
e

Endre Karlson

02/12/2024, 4:57 PM
Dynamic workflows yeah
s

Samhita Alla

02/12/2024, 5:15 PM
you should be able to catch exceptions using eager workflows: https://docs.flyte.org/en/latest/flytesnacks/examples/advanced_composition/eager_workflows.html#catching-exceptions. can you give it a try?
e

Endre Karlson

02/12/2024, 5:18 PM
So exceptions can't be catched inside of tasks ?
s

Samhita Alla

02/12/2024, 5:38 PM
yes, it works only in eager workflows.
e

Endre Karlson

02/12/2024, 6:06 PM
So with EagerException you can't get the inner Exception ? 🤔
little bit hopeless then to actually know what exception it is
s

Samhita Alla

02/13/2024, 8:12 AM
I don’t think you can get the inner exception. @Niels Bantilan could you confirm?
n

Niels Bantilan

02/13/2024, 2:37 PM
You can’t right now. @Endre Karlson would you mind opening an enhancement ticket for this? The challenge is that inside an eager workflow, tasks are executed using
FlyteRemote
and there isn’t a principled way of extracting the original exception, besides doing some fairly hacky string parsing
Dynamic workflows yeah
Wait are you using dynamic workflows or eager workflows?
e

Endre Karlson

02/13/2024, 4:16 PM
Dynamic workflows calling Workflows -> Tasks
fan out
n

Niels Bantilan

02/13/2024, 4:22 PM
so with dynamic workflows you can’t use the try/except pattern when executing flyte entities
Copy code
@task
def my_task(x: int) -> int: ...

@dynamic
def wf(x: int) -> list[int]:
    # x is an actual python value
    try: # this works because inputs are materialized in dynamic workflows
        x + "foo"
    except TypeError:
       ...

    results = [] 
    for x in range(x):
        try:
            results.append(my_task(x=x))
        except Exception:
            ... # this won't work because Flyte uses the for loop to will implicitly compile a Flyte workflow

    return results