-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: using pytask.task()(func_defined_in_other_file)
doesn't work
#513
Comments
Possible fix for pytask-dev#513 I didn't add any tests yet until I got confirmation this is the right direction.
Ehh, actually the solution of using the module where pytask.task() was called will fall apart if I have some make_task() wrapper in my_tasks.py, since then it will always be "my_tasks.py". Why do we even need to store tasks in a dict? Is that only needed for automatic collection, but when using the programmatic interface should it work a different way? Can/should we add a param to task() so you can override the module where the task is supposed to live? |
As a workaround, does wrapping it in |
yes that does work, but long term it would be nice if that wasn't required. |
In #521 I added an error message that tells the user about tasks that have not been collected and that the tasks need to be wrapped with a lambda. So, you would have at least received an error in your case.
It is to prevent garbage-collecting tasks defined in a loop that will be overwritten in the next iteration. The dictionary could be replaced by anything else that keeps the objects alive.
This could be an option. The injected path would be used to store the function, and it would be collected with the correct module. But I am unsure how I feel about it. I am also wondering what the more reasonable assumption is to determine the task module of a function wrapped with What are the use cases we have?
What if we walk up the call stack when |
Can we take a step back and question: why does a task need to have a For CLI-discovered tasks (eg a But for programmatically-defined tasks (eg created with |
I agree that tasks passed via the programmatic interface The linked PR fixes that and allows setting the module name via the I still have to see whether it conflicts with code in pytask-paralle. The path is used as a fallback if the function does not yield a path. |
Wait wait, if we can I really think we should try to avoid adding this argument to .task(). Why does a task need to have a module attribute? I'm wondering if we can just get rid of that requirement for programmatically defined tasks? I'm probably missing something obvious and there is a real reason they do, but I want to double check. Thanks! |
Hi! Belated happy holidays and a happy new year! Sorry for skipping right to a change without answering your question. I appreciate it. Let's dig deeper and see whether we find a better solution. And, sorry for the lengthy response. I am trying to figure out how to best look at the problem. A bit of background on why there is a path attribute. There are currently two kinds of tasks,
A task decorated with The
What are possible solutions? 2-4 are more cosmetic, and five would be a bigger change.
|
main
branch of pytask.Code Sample, a copy-pastable example
zipped dir: tasks.zip
Problem description
It appears that in
pytask.task()
, the created task is stored inCOLLECTED_TASKS
,but is stored under
COLLECTED_TASKS["lib.py"]
(the place where the function was defined), not underCOLLECTED_TASKS["task_bug.py"]
(where the task was created). Then, when we actually go looking throughCOLLECTED_TASKS
for tasks to execute, we miss it because we only look under "task_bug.py"Expected Output
I think the created task should be stored under
COLLECTED_TASKS["task_bug.py"]
where the task was created.The text was updated successfully, but these errors were encountered: