https://prefect.io logo
n

Newskooler

11/13/2020, 8:21 PM
Hi đŸ‘‹ , I am running a very straight forward Flow and I got this error:
ValueError: Could not infer an active Flow context.
I find it quite cryptic. Can anyone please shed some light on what my issue may be? I have no clue right now : /
n

nicholas

11/13/2020, 8:25 PM
Hi @Newskooler - would you mind sharing some of your code?
n

Newskooler

11/13/2020, 8:38 PM
Sure, I condensed it to the essential structure:
Copy code
@task
def extract() -> list:
    return get_info()


@task
def transform(raw_data: list) -> pd.DataFrame:
    return transform(raw_data)


@task
def save(mapped_data: pd.DataFrame) -> None:
    x = list(set(mapped_data.columns) & set(['a', 'b', 'c']))
    y = list(set(mapped_data.columns) & set(['1', '2', '3']))
    save_data(
        dataframe=mapped_data,
        x_axis=x,
        y_axis=y,
    )


with Flow(name='some name') as flow:
    raw_data = extract()
    mapped_data = transform(raw_data)
    save(mapped_data)

flow.storage = Local(directory='/some/location')
n

nicholas

11/13/2020, 8:39 PM
What happens when you remove the
save_data
call?
n

Newskooler

11/13/2020, 8:39 PM
1 moment…
it does not fail
n

nicholas

11/13/2020, 8:42 PM
Ok good, that narrows it down. Something in your
save_data
method is trying to reference the flow context; is
save_data
a task?
n

Newskooler

11/13/2020, 8:43 PM
Yes. I will look into the inputs there.
Thanks!
n

nicholas

11/13/2020, 8:44 PM
If that's the case, try returning the inputs from
save
and passing those to an explicit task call of
save_data
in the
with Flow() as flow:
block đŸ™‚
n

Newskooler

11/13/2020, 8:45 PM
ohh.. this may be it… It’s a
task
inside a
task
n

nicholas

11/13/2020, 8:45 PM
Exactly!
n

Newskooler

11/13/2020, 8:47 PM
Thanks : ))
n

nicholas

11/13/2020, 8:48 PM
đŸ˜„