When doing a query for a report we have some time ...
# ask-the-community
e
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
hi @Endre Karlson! are you using eager workflows?
e
Dynamic workflows yeah
s
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
So exceptions can't be catched inside of tasks ?
s
yes, it works only in eager workflows.
e
So with EagerException you can't get the inner Exception ? 🤔
little bit hopeless then to actually know what exception it is
s
I don’t think you can get the inner exception. @Niels Bantilan could you confirm?
n
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
Dynamic workflows calling Workflows -> Tasks
fan out
n
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