Hi is there a way to inspect if/where the targets ...
# ask-community
a
Hi is there a way to inspect if/where the targets of a task was ultimately saved after running
flow_result = flow.run(...)
? I'm missing a couple of output files and I have no idea where they are saved so trying to hunt them down to prevent memory leak (not in my expected folder and also not in
~/.prefect/results
)
a
@An Hoang can you share how you define Results in your flow?
k
It sounds like you may have defined an absolute path when trying to do a relative path? Unsure, but yeah showing how you defined it would help
a
hopefully will write up something this weekend when I have a chance. Encountered bizarre behavior... or maybe I missed something obvious I usually define the targets and results at the task level. All my tasks are like this
Copy code
@task(target=target_file_str, result = LocalResult(dir="./test_prefect"))
def task_A(...):
    helper_func_A()
I need to change directory for specific tasks/part of the flow. Here is my code for changing directory, mimicking
cd
in bash
Copy code
from functools import wraps
from contextlib import contextmanager

@contextmanager
def cd(newdir):
    prevdir = os.getcwd()
    os.chdir(os.path.expanduser(newdir))
    try:
        yield
    finally:
        os.chdir(prevdir)

def change_cwd_dir(new_dir):
    def decorator(func):
        @wraps(func)
        def wrapped_func(*args, **kwargs):
            with cd(new_dir):
                func_result = func(*args, **kwargs)
            return func_result
        return wrapped_func
    return decorator
1. Changing where I call
flow.run
Copy code
with cd("new/dir"):
    flow.run(...)
2. Changing directory within a task
Copy code
@task(target=target_file_str, result = LocalResult(dir="./test_prefect"))
def task_A(...):
    with cd("new/dir"):
        helper_func_A()
3. Wrapping it around a decorator before wrapping it with
task
Copy code
@task(target=target_file_str, result = LocalResult(dir="./test_prefect"))
@change_cwd_dir("new/dir")
def task_A(...):
    helper_func_A()
None of these worked. Some targets went to the correct directory
./test_prefect
, some were at the wrong place , some went to
~/.prefect/results
and some went somewhere that I don't know, but I'm sure it was persisted because those tasks were skipped in a repeat run. The wrong directories are not related to
new/dir
It was a humbling and frustrating experience 😅. Any insights as to what might have went wrong here?
k
Oh man this is real tricky lol. Did you try debug level logs? I think those show the result locations
a
Probably will table it for now while I work on some other flows. Right now I'm just gonna do all the work to navigate to the right directory and then start the
prefect run
process there lol... Definitely needs to be looked at though. I think since the context change, it changes the meaning of where
./test_prefect
is