{"record":{"id":"c2356e4cfdacd647","repo":"apache/dolphinscheduler","slug":"workflow-definition-not-found-workflowdefinition","errorCode":null,"errorMessage":"Workflow definition not found: <workflowDefinitionCode> version: <workflowDefinitionVersion>","messagePattern":"Workflow definition not found: <workflowDefinitionCode> version: <workflowDefinitionVersion>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/trigger/AbstractWorkflowInstanceTrigger.java","lineNumber":62,"sourceCode":"    @Autowired\n    private CommandDao commandDao;\n\n    @Autowired\n    protected SerialCommandDao serialCommandDao;\n\n    @Autowired\n    protected WorkflowDefinitionLogDao workflowDefinitionLogDao;\n\n    @Override\n    @Transactional\n    public TriggerResponse triggerWorkflow(final TriggerRequest triggerRequest) {\n        final WorkflowInstance workflowInstance = constructWorkflowInstance(triggerRequest);\n        final Long workflowDefinitionCode = workflowInstance.getWorkflowDefinitionCode();\n        final int workflowDefinitionVersion = workflowInstance.getWorkflowDefinitionVersion();\n        final WorkflowDefinitionLog workflowDefinition = workflowDefinitionLogDao.queryByDefinitionCodeAndVersion(\n                workflowDefinitionCode, workflowDefinitionVersion);\n        if (workflowDefinition == null) {\n            throw new IllegalStateException(\n                    \"Workflow definition not found: \" + workflowDefinitionCode + \" version: \"\n                            + workflowDefinitionVersion);\n        }\n        final Command command = constructTriggerCommand(triggerRequest, workflowInstance);\n        if (workflowDefinition.getExecutionType() == WorkflowExecutionTypeEnum.PARALLEL) {\n            workflowInstanceDao.updateById(workflowInstance);\n            commandDao.insert(command);\n        } else {\n            workflowInstance.setState(WorkflowExecutionStatus.SERIAL_WAIT);\n            workflowInstanceDao.updateById(workflowInstance);\n            serialCommandDao.insert(SerialCommandDto.newSerialCommand(command).toEntity());\n        }\n\n        return onTriggerSuccess(workflowInstance);\n    }\n\n    // todo: 使用WorkflowInstanceConstructor封装\n    protected abstract WorkflowInstance constructWorkflowInstance(final TriggerRequest triggerRequest);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/trigger/AbstractWorkflowInstanceTrigger.java#L44-L80","documentation":"Thrown during workflow triggering when the requested workflow definition (by code and version) cannot be found in the definition log table. The master resolves the exact published snapshot (code + version) before constructing the trigger command; if the snapshot was deleted, unpublished, or the version never existed, the trigger cannot proceed and an IllegalStateException is raised.","triggerScenarios":"Calling any trigger API (schedule, complement, retry, fault-tolerant trigger built on AbstractWorkflowInstanceTrigger) with a workflowDefinitionCode/version pair absent from t_ds_workflow_definition_log — e.g. querying a stale version after the definition was re-versioned or deleted.","commonSituations":"Workflow was deleted or offline while schedules/complements still reference it; metadata cleanup removed old definition-log rows; replica/master DB out of sync; API caller hardcoded an outdated version number.","solutions":["Confirm the code/version in t_ds_workflow_definition_log: SELECT * WHERE code=? AND version=?; re-publish the workflow if missing.","Delete or correct the stale schedule/complement/retry reference pointing to the deleted version.","Use the current version from t_ds_workflow_definition instead of a hardcoded version when calling trigger APIs.","Restore the definition-log row from backup or re-import the workflow JSON if the deletion was accidental."],"exampleFix":"// before\nmaster.triggerWorkflow(WorkflowTriggerRequest.of(code, oldVersion));\n// after\nWorkflowDefinition latest = queryLatestDefinition(code);\nmaster.triggerWorkflow(WorkflowTriggerRequest.of(code, latest.getVersion()));","handlingStrategy":"validation","validationCode":"WorkflowDefinitionLog def = workflowDefinitionLogDao.queryByDefinitionCodeAndVersion(code, version);\nif (def == null) {\n    throw new IllegalArgumentException(\"Definition not found: \" + code + \" v\" + version);\n}\n// safe to trigger","typeGuard":"boolean definitionExists(long code, int version) {\n    return workflowDefinitionLogDao.queryByDefinitionCodeAndVersion(code, version) != null;\n}","tryCatchPattern":"try {\n    triggerResponse = master.triggerWorkflow(request);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Workflow definition not found\")) {\n        log.error(\"Stale definition code/version: {}\", e.getMessage());\n        // refresh version or remove stale schedule\n    }\n}","preventionTips":["Resolve the current version from t_ds_workflow_definition instead of hardcoding","Clean up schedules/complements when deleting or re-versioning workflows","Don't purge t_ds_workflow_definition_log rows still referenced by triggers","Check definition existence in the UI/API before automated triggering"],"tags":["workflow-trigger","not-found","definition","database"],"backgroundTag":"entity-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}