<@ULVA73B9P> I have what feels like an incredibly ...
# ask-marvin
m
@Marvin I have what feels like an incredibly naive question. I have this sample code:
Copy code
from prefect import flow, task

@flow
def my_flow():
    for i in range(0, 4):
        task_n(i)

@task()
def task_n(i:int):
    print(i)

if __name__ == "__main__":
    my_flow()
I'm trying to see the input passed to
task_n
(I expect
i=0
,
i=1
, etc) but for all the tasks, the input is displayed as:
Copy code
{
  "i": []
}
I also executed:
Copy code
prefect config set PREFECT_RESULTS_PERSIST_BY_DEFAULT=true
and got the same result. This happens whether I'm running a local server or using the cloud server. I feel like I'm missing something super obvious, any hints?
m
It seems you're encountering an issue with Prefect where the task input is displayed as an empty list. This is likely related to how Prefect handles task inputs and results in version 3.x. Here's what I found: 1. Result Persistence: The setting
PREFECT_RESULTS_PERSIST_BY_DEFAULT=true
enables result persistence, which ensures that task results are stored and can be retrieved later. However, this setting alone doesn't affect how inputs are displayed or passed to tasks. More on result persistence here. 2. Common Gotchas: In Prefect 3.x, there are some key changes and common pitfalls: - Prefect 3.x uses Pydantic 2, which might affect how data types are handled. - Ensure that task inputs are appropriately typed and that you're not facing a type mismatch issue. 3. Debugging Steps: - Double-check that the
task
decorator is properly applied and that there are no hidden syntax errors. - Try logging the input
i
directly within the
task_n
function to see if it prints correctly before reaching Prefect's internal handling. 4. Further Investigation: If the problem persists, consider exploring the Prefect GitHub repository for any open issues related to task input handling in Prefect 3.x. If none of these suggestions resolve the issue, it might be worth raising a bug report with the Prefect team. You can also explore the Prefect GitHub repository for similar issues or updates.
n
we should make this more obvious in the UI, but there's a tooltip explaining that task run "inputs" are not actually the task run parameter values .... which is kinda 🫠 I know
💡 1
"Inputs" here means references to upstream task results, ie upstream state deps
we don't actually store task run params in the API at all
m
aha, okay, that makes sense! So if I wanted to store task params, I'd need to set that up manually (by eg. extending @task into my own custom thing or making a new decorator)
is there a standard way to use task caching to do this?
(I'm super new to Prefect, obviously, so forgive my naivete!)
n
no worries! can you give some color on what you're trying to do? using
cache_policy
might be something to check out https://docs.prefect.io/v3/develop/task-caching#configure-task-caching
also you may find this useful for getting oriented https://www.youtube.com/@natefromprefect5895/playlists
👍 1
m
What I would like to do is make it so that, if a given task run does something unexpected, I can run a little command-line script and turn that task execution into a unit test -- so create a pytest function that calls the function specified by that task with the parameters passed to it in that run.
ideally I could hit an API with the task run ID and get the values of the parameters
but it's fine if that API isn't on Prefect, it could be on a file in S3 or a SQLite db locally or whatever -- I can wire that up