{"record":{"id":"060a796f219161cb","repo":"tursodatabase/turso","slug":"no-sql-in-batch-step","errorCode":null,"errorMessage":"No SQL in batch step","messagePattern":"No SQL in batch step","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli/sync_server.rs","lineNumber":534,"sourceCode":"            }\n            BatchCond::And(list) => list\n                .conds\n                .iter()\n                .all(|c| Self::evaluate_condition(c, step_results, step_errors, conn)),\n            BatchCond::Or(list) => list\n                .conds\n                .iter()\n                .any(|c| Self::evaluate_condition(c, step_results, step_errors, conn)),\n            BatchCond::IsAutocommit {} => conn.get_auto_commit(),\n        }\n    }\n\n    fn execute_batch_step(&self, conn: &Arc<Connection>, step: &BatchStep) -> Result<StmtResult> {\n        let sql = step\n            .stmt\n            .sql\n            .as_ref()\n            .ok_or_else(|| anyhow!(\"No SQL in batch step\"))?;\n\n        debug!(\"Executing batch step SQL: {}\", sql);\n\n        let mut stmt = conn.prepare(sql)?;\n\n        for (i, arg) in step.stmt.args.iter().enumerate() {\n            let core_value = convert_value_to_core(arg);\n            stmt.bind_at(std::num::NonZero::new(i + 1).unwrap(), core_value)?;\n        }\n\n        let want_rows = step.stmt.want_rows.unwrap_or(true);\n\n        if want_rows {\n            let rows = stmt.run_collect_rows()?;\n\n            let cols: Vec<Col> = (0..stmt.num_columns())\n                .map(|i| Col {\n                    name: Some(stmt.get_column_name(i).to_string()),","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L516-L552","documentation":"While executing a /v2/pipeline batch, a BatchStep's statement had stmt.sql == None and this server cannot run it: execute_batch_step always prepares SQL by string (conn.prepare(sql)). The wire type makes sql optional (clients may reference previously cached statements), but this implementation has no statement cache and requires SQL text on every step.","triggerScenarios":"Sending a batch whose step looks like {\"stmt\": {\"sql\": null, \"args\": [...]}} or that omits the sql key entirely; typically a client relying on prepared-statement reuse the sync server never implemented.","commonSituations":"Client SDK versions that omit sql for cached statements; hand-built batch JSON where the sql field was dropped when converting an Execute request into a Batch step; integration tests constructing BatchStep structs directly without setting sql.","solutions":["Set a non-empty sql string on every statement of every batch step before sending","If using a client library, disable statement caching/reuse for sync-server traffic so sql is always included","Validate the outgoing payload: every requests[].stmt.sql must be a non-empty string"],"exampleFix":"// before\n{\"Batch\": {\"steps\": [{\"stmt\": {\"args\": [1]}}]}}\n\n// after\n{\"Batch\": {\"steps\": [{\"stmt\": {\"sql\": \"INSERT INTO t VALUES (?)\", \"args\": [1]}}]}}","handlingStrategy":"validation","validationCode":"for (const step of batch.steps) {\n  if (typeof step?.stmt?.sql !== 'string' || step.stmt.sql.trim() === '') {\n    throw new Error(`batch step is missing stmt.sql: ${JSON.stringify(step)}`);\n  }\n}","typeGuard":"function hasSql(step: unknown): step is { stmt: { sql: string } } {\n  return typeof (step as any)?.stmt?.sql === 'string' && (step as any).stmt.sql.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Construct batch steps through the SDK types so sql is a required compile-time field where possible","Disable client statement caching/reuse against this server so sql is always sent","Assert every step has sql in a unit test over the request builder"],"tags":["sync-server","batch","statement","missing-sql"],"backgroundTag":"missing-required-argument","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}