{"record":{"id":"8e6defbbe8434532","repo":"apache/dolphinscheduler","slug":"sql-task-params-is-not-valid","errorCode":null,"errorMessage":"sql task params is not valid","messagePattern":"sql task params is not valid","errorType":"validation","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java","lineNumber":106,"sourceCode":"    /**\n     * default query sql limit\n     */\n    private static final int QUERY_LIMIT = 10000;\n\n    private final SQLTaskExecutionContext sqlTaskExecutionContext;\n\n    private final DbType dbType;\n\n    private Connection sessionConnection;\n    private Statement sessionStatement;\n\n    public SqlTask(TaskExecutionContext taskRequest) {\n        super(taskRequest);\n        this.taskExecutionContext = taskRequest;\n        this.sqlParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), SqlParameters.class);\n        log.info(\"Initialize sql task parameter {}\", JSONUtils.toPrettyJsonString(sqlParameters));\n        if (sqlParameters == null || !sqlParameters.checkParameters()) {\n            throw new TaskException(\"sql task params is not valid\");\n        }\n        if (this.sqlParameters.getDatasource() == 0) {\n            throw new TaskException(\"unbound test data source\");\n        }\n\n        sqlTaskExecutionContext =\n                sqlParameters.generateExtendedContext(taskExecutionContext.getResourceParametersHelper());\n        dbType = DbType.valueOf(sqlParameters.getType());\n    }\n\n    @Override\n    public AbstractParameters getParameters() {\n        return sqlParameters;\n    }\n\n    @Override\n    public void handle(TaskCallBack taskCallBack) throws TaskException {\n        log.info(\"Full sql parameters: {}\", sqlParameters);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java#L88-L124","documentation":"The SqlTask constructor parses the task params JSON into SqlParameters and immediately validates: if parsing fails (null result) or checkParameters() returns false, it throws TaskException(\"sql task params is not valid\"). checkParameters() requires non-empty sql (or a non-empty pre/post statement) plus a type; a SQL task instance cannot even be constructed without them.","triggerScenarios":"taskExecutionContext.getTaskParams() is null, empty, malformed JSON, or yields SqlParameters with an empty sql field and empty preStatements/postStatements, or a blank type.","commonSituations":"SQL task node saved with an empty SQL editor; datasource plugin upgrade changing SqlParameters field names so old JSON no longer deserializes; API workflow import with truncated taskParams JSON; invalid characters breaking JSONUtils parsing.","solutions":["Open the SQL task node, ensure the SQL statement is non-empty and a database type is selected, then re-save","Validate the stored task params JSON parses into SqlParameters with checkParameters()==true before scheduling the workflow","If this appeared after an upgrade/re-import, re-export/re-import the workflow definition and confirm taskParams fields match the current SqlParameters schema"],"exampleFix":"// before\n{\"taskType\":\"SQL\",\"taskParams\":{\"type\":\"MYSQL\",\"datasource\":3}}\n// after (sql must be non-empty)\n{\"taskType\":\"SQL\",\"taskParams\":{\"type\":\"MYSQL\",\"datasource\":3,\"sql\":\"select 1\"}}","handlingStrategy":"validation","validationCode":"SqlParameters p = JSONUtils.parseObject(taskParams, SqlParameters.class);\nif (p == null || !p.checkParameters()) {\n    throw new IllegalArgumentException(\"sql params invalid: sql and type must be non-empty\");\n}","typeGuard":"boolean isValidSqlParams(String json) {\n    SqlParameters p = JSONUtils.parseObject(json, SqlParameters.class);\n    return p != null && p.checkParameters();\n}","tryCatchPattern":"try {\n    SqlTask task = new SqlTask(taskExecutionContext); // throws in constructor\n} catch (TaskException e) {\n    // params missing/invalid: fix taskParams JSON before retry\n}","preventionTips":["Never save a SQL node with an empty SQL editor or blank database type","Validate taskParams against SqlParameters schema when importing/exporting workflows","Re-import definitions cleanly after plugin upgrades that change parameter fields"],"tags":["sql","validation","task-params"],"backgroundTag":"schema-validation-failed","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"}