{"record":{"id":"198787ace89c4c96","repo":"apache/cassandra","slug":"invalid-consistency-for-conditional-update-must-b","errorCode":null,"errorMessage":"Invalid consistency for conditional update. Must be one of SERIAL or LOCAL_SERIAL","messagePattern":"Invalid consistency for conditional update\\. Must be one of SERIAL or LOCAL_SERIAL","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/ConsistencyLevel.java","lineNumber":260,"sourceCode":"    public void validateForCasCommit(AbstractReplicationStrategy replicationStrategy) throws InvalidRequestException\n    {\n        switch (this)\n        {\n            case EACH_QUORUM:\n                requireNetworkTopologyStrategy(replicationStrategy);\n                break;\n            case SERIAL:\n            case UNSAFE_DELAY_SERIAL:\n            case LOCAL_SERIAL:\n            case UNSAFE_DELAY_LOCAL_SERIAL:\n                throw new InvalidRequestException(this + \" is not supported as conditional update commit consistency. Use ANY if you mean \\\"make sure it is accepted but I don't care how many replicas commit it for non-SERIAL reads\\\"\");\n        }\n    }\n\n    public void validateForCas() throws InvalidRequestException\n    {\n        if (!isSerialConsistency())\n            throw new InvalidRequestException(\"Invalid consistency for conditional update. Must be one of SERIAL or LOCAL_SERIAL\");\n    }\n\n    public boolean isSerialConsistency()\n    {\n        switch (this)\n        {\n            case SERIAL:\n            case UNSAFE_DELAY_SERIAL:\n            case LOCAL_SERIAL:\n            case UNSAFE_DELAY_LOCAL_SERIAL:\n                return true;\n            default:\n                return false;\n        }\n    }\n\n    public void validateCounterForWrite(TableMetadata metadata) throws InvalidRequestException\n    {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/ConsistencyLevel.java#L242-L278","documentation":"validateForCas ensures the serial consistency used for a lightweight transaction is one of SERIAL or LOCAL_SERIAL. Any other level passed as the serial consistency of a conditional update is rejected, because Paxos phases only support these two serial modes.","triggerScenarios":"Calling execute with a conditional update whose serial consistency is set to something like QUORUM, ONE, or SERIAL-derived UNSAFE variants not accepted, e.g. stmt.setSerialConsistencyLevel(ConsistencyLevel.QUORUM).","commonSituations":"Application-wide consistency settings accidentally applied to the serial consistency slot; old drivers exposing serial consistency incorrectly; copy-pasted consistency configuration.","solutions":["Set the serial consistency to ConsistencyLevel.SERIAL (default) or LOCAL_SERIAL.","Keep regular (commit) consistency separate; only the serial slot is validated here.","Audit code that copies one consistency enum into both consistency and serial-consistency parameters.","In cqlsh use `SERIAL CONSISTENCY LOCAL_SERIAL;` with only those two values."],"exampleFix":"// before\nstmt.setSerialConsistencyLevel(ConsistencyLevel.QUORUM);\n// after\nstmt.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL);","handlingStrategy":"validation","validationCode":"// Guard serial CL before LWT execution\nif (serialCl != ConsistencyLevel.SERIAL && serialCl != ConsistencyLevel.LOCAL_SERIAL)\n    throw new IllegalArgumentException(\"serial CL must be SERIAL or LOCAL_SERIAL\");","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"Invalid consistency for conditional update\")) {\n        statement.setSerialConsistencyLevel(ConsistencyLevel.SERIAL);\n        retry();\n    } else throw e;\n}","preventionTips":["Rely on the driver default (SERIAL) unless LOCAL_SERIAL is specifically needed.","Do not propagate application-wide consistency enums into the serial-consistency parameter.","In cqlsh use `SERIAL CONSISTENCY` only with SERIAL/LOCAL_SERIAL.","Centralize LWT execution in one helper that enforces valid serial levels."],"tags":["cassandra","consistency-level","lwt","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}