{"record":{"id":"24602ef6d0e02d49","repo":"apache/cassandra","slug":"invalid-empty-consistency-level","errorCode":null,"errorMessage":"Invalid empty consistency level","messagePattern":"Invalid empty consistency level","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/BatchStatement.java","lineNumber":506,"sourceCode":"                                                    tableNames.size() == 1 ? \"\" : \"s\", tableNames}).getMessage());\n            }\n        }\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","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L488-L524","documentation":"BatchStatement.execute requires a non-null consistency level on the BatchQueryOptions. If the consistency level was never set (left null) the coordinator cannot determine the required replication ack count, so it throws InvalidRequestException 'Invalid empty consistency level'.","triggerScenarios":"Programmatic execution of a BatchStatement where QueryOptions/BatchQueryOptions was constructed without calling setConsistency; native protocol frames missing the consistency field; internal callers bypassing statement preparation.","commonSituations":"Custom drivers/tools building batch options manually; embedded usage of Cassandra internals (e.g. tests or tools calling execute directly); protocol-level clients omitting the CL field.","solutions":["Set the consistency level explicitly before executing (options.setConsistency(ConsistencyLevel.QUORUM) or QUORUM-level equivalent in your driver)","If using a driver, ensure the request includes a consistency level (or configure a default CL in the driver)","Fix internal tooling to populate BatchQueryOptions consistency rather than passing null"],"exampleFix":"// before\nBatchQueryOptions opts = BatchQueryOptions.forStatement(statements, rawOptions); // CL unset\nbatch.execute(queryState, opts, requestTime);\n// after\nrawOptions.setConsistency(ConsistencyLevel.QUORUM);\nbatch.execute(queryState, BatchQueryOptions.forStatement(statements, rawOptions), requestTime);","handlingStrategy":"validation","validationCode":"if (options.getConsistency() == null) options.setConsistency(ConsistencyLevel.QUORUM);","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"Invalid empty consistency\")) { setDefaultClAndRetry(); } else throw e; }","preventionTips":["Always build query options through helpers that set a default CL","In drivers, configure a default consistency level instead of leaving it unset"],"tags":["cql","batch","consistency-level","invalid-request"],"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"}