{"record":{"id":"d2dd8891ebf78f7d","repo":"apache/cassandra","slug":"invalid-empty-serial-consistency-level","errorCode":null,"errorMessage":"Invalid empty serial consistency level","messagePattern":"Invalid empty serial consistency level","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/BatchStatement.java","lineNumber":508,"sourceCode":"        }\n    }\n\n\n    @Override\n    public ResultMessage execute(QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)\n    {\n        return execute(queryState, BatchQueryOptions.withoutPerStatementVariables(options), requestTime);\n    }\n\n    public ResultMessage execute(QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime)\n    {\n        long timestamp = options.getTimestamp(queryState);\n        long nowInSeconds = options.getNowInSeconds(queryState);\n\n        if (options.getConsistency() == null)\n            throw new InvalidRequestException(\"Invalid empty consistency level\");\n        if (options.getSerialConsistency() == null)\n            throw new InvalidRequestException(\"Invalid empty serial consistency level\");\n\n        ClientState clientState = queryState.getClientState();\n        if (Guardrails.writeConsistencyLevels.enabled(clientState)) // to avoid EnumSet allocation\n            Guardrails.writeConsistencyLevels.guard(EnumSet.of(options.getConsistency(),\n                                                               options.getSerialConsistency()),\n                                                    clientState);\n\n        // resolved once for the whole batch, the guardrail checks are not cheap enough to repeat per statement\n        DiskUsageCheck diskUsageCheck = ModificationStatement.diskUsageCheck(clientState);\n        if (diskUsageCheck != DiskUsageCheck.NONE)\n            for (int i = 0; i < statements.size(); i++)\n                statements.get(i).validateDiskUsage(options.forStatement(i), clientState, diskUsageCheck);\n\n        if (hasConditions)\n            return executeWithConditions(options, queryState, requestTime);\n\n        if (updatesVirtualTables)\n            executeInternalWithoutCondition(queryState, options, requestTime);","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L490-L526","documentation":"For batches, the serial consistency level (used for lightweight-transaction coordination via Paxos) must also be explicitly set. execute() throws InvalidRequestException when options.getSerialConsistency() is null, immediately after the plain consistency check.","triggerScenarios":"Executing a batch via execute() with BatchQueryOptions whose serialConsistency was never populated — e.g. conditional (LWT) batches or programmatic callers that set only the regular consistency level.","commonSituations":"Custom protocol implementations omitting the serial CL field; internal tools constructing query options manually; driver versions with incomplete SERIAL_CL support on batch messages.","solutions":["Set the serial consistency explicitly (options.setSerialConsistency(ConsistencyLevel.SERIAL) or LOCAL_SERIAL)","Ensure the driver/client sends the serial consistency field on the BATCH message","Only relevant for LWT batches in practice — populate serial CL defaults in any internal option builder"],"exampleFix":"// before\nBatchQueryOptions opts = ...; opts.setConsistency(ConsistencyLevel.QUORUM); // serial unset\n// after\nopts.setConsistency(ConsistencyLevel.QUORUM);\nopts.setSerialConsistency(ConsistencyLevel.LOCAL_SERIAL);","handlingStrategy":"validation","validationCode":"if (options.getSerialConsistency() == null) options.setSerialConsistency(ConsistencyLevel.SERIAL);","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"serial consistency\")) { setDefaultSerialClAndRetry(); } else throw e; }","preventionTips":["Set both consistency and serial consistency whenever constructing BatchQueryOptions","Use SERIAL/LOCAL_SERIAL defaults in any internal LWT option builder"],"tags":["cql","batch","serial-consistency","lwt"],"backgroundTag":"missing-required-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}