zhuangchong opened a new issue, #18733: URL: https://github.com/apache/dolphinscheduler/issues/18733
### Search before asking - [x] I searched the existing issues and found no similar issue. ### What happened Switching a workflow to a non-current version can fail with error `20016` because datasource permission validation includes unrelated historical tasks. The unrelated task definitions can also be passed to workflow lineage persistence. This affects switching to a non-current version. Switching to the current version can still find relations in the main relation table. ### What you expected to happen Datasource and sub-workflow permission checks, as well as workflow lineage updates, should only use tasks referenced by the target workflow version. ### How to reproduce 1. Create multiple workflow versions so the target version is not the current version. 2. Ensure an unrelated historical task references a datasource unavailable to the current user. 3. Switch the workflow to the older version. 4. The switch fails with `RESOURCE_NOT_EXIST_OR_NO_PERMISSION` (`20016`). ### Root cause `WorkflowDefinitionServiceImpl.switchWorkflowDefinitionVersion` queries `t_ds_workflow_task_relation` with the target version before calling `processService.switchVersion`. The main relation table only stores the current version, so querying a non-current target version returns an empty list. Passing the resulting empty task collection to `TaskDefinitionLogMapper.queryByTaskDefinitions` removes the dynamic predicate and leaves `WHERE 1 = 1`, scanning all task definition logs. The ordering was introduced by #18566 when permission validation was moved before `switchVersion`. ### Proposed fix Read relations for the target version from `t_ds_workflow_task_relation_log`, and skip the task-definition query when the target relation set is empty. -- 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]
