zhongjiajie opened a new issue #6658:
URL: https://github.com/apache/dolphinscheduler/issues/6658


   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   
   ### What happened
   
   When I define workflow by code using python, it failed with not exists task. 
My code definitions as below:
   
   ```py
   from pydolphinscheduler.core.process_definition import ProcessDefinition
   from pydolphinscheduler.tasks.shell import Shell
   
   # make sure your tenant exists
   tenant = "zhongjiajie"
   
   num_workflows = 100
   num_tasks = 10
   # Whether task should dependent or not, if True would create dependent like 
`pre-task -> task -> next-task`
   is_chain = True
   
   for wf in range(0, num_workflows):
       with ProcessDefinition(name=f"wf:{wf}", tenant=tenant) as pd:
           for t in range(0, num_tasks):
               task = Shell(name=f"task:{t}-wf:{wf}", command=f"echo task {t}")
               if is_chain and t > 0:
                   pre_task_name = f"task:{t-1}-wf:{wf}"
                   pd.get_one_task_by_name(pre_task_name) >> task
           pd.submit()
   ```
   
   It would sometime failed with error
   
   ```log
   ValueError: Can not find task with name task:1-wf:0
   ```
   
   or something like that. I debug and find it due to 
   
https://github.com/apache/dolphinscheduler/blob/dev/dolphinscheduler-python/src/main/java/org/apache/dolphinscheduler/server/PythonGatewayServer.java#L132-L135.
 Python code run so fast, then we get same `code` and in 
   
https://github.com/apache/dolphinscheduler/blob/daca3baf6662b9bcf3de856722ece79aad753773/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/task.py?_pjax=%23js-repo-pjax-container#L149-L150
   task do not add to workflow
   
   ### What you expected to happen
   
   Should not get error
   
   ### How to reproduce
   
   run what I paste above
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to