{"record":{"id":"58637ad0b6f15541","repo":"apache/cassandra","slug":"the-updates-generated-by-triggers-are-not-all-for","errorCode":null,"errorMessage":"The updates generated by triggers are not all for the same partition","messagePattern":"The updates generated by triggers are not all for the same partition","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/triggers/TriggerExecutor.java","lineNumber":195,"sourceCode":"        List<Mutation> merged = new ArrayList<>(groupedMutations.size());\n        for (Pair<String, ByteBuffer> key : groupedMutations.keySet())\n            merged.add(Mutation.merge(groupedMutations.get(key)));\n\n        return merged;\n    }\n\n    private List<PartitionUpdate> validateForSinglePartition(TableId tableId,\n                                                             DecoratedKey key,\n                                                             Collection<Mutation> tmutations)\n    throws InvalidRequestException\n    {\n        validate(tmutations);\n\n        if (tmutations.size() == 1)\n        {\n            List<PartitionUpdate> updates = Lists.newArrayList(Iterables.getOnlyElement(tmutations).getPartitionUpdates());\n            if (updates.size() > 1)\n                throw new InvalidRequestException(\"The updates generated by triggers are not all for the same partition\");\n            validateSamePartition(tableId, key, Iterables.getOnlyElement(updates));\n            return updates;\n        }\n\n        ArrayList<PartitionUpdate> updates = new ArrayList<>(tmutations.size());\n        for (Mutation mutation : tmutations)\n        {\n            for (PartitionUpdate update : mutation.getPartitionUpdates())\n            {\n                validateSamePartition(tableId, key, update);\n                updates.add(update);\n            }\n        }\n        return updates;\n    }\n\n    private void validateSamePartition(TableId tableId, DecoratedKey key, PartitionUpdate update)\n    throws InvalidRequestException","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/triggers/TriggerExecutor.java#L177-L213","documentation":"When a trigger augments a single-partition mutation, all PartitionUpdates produced by the trigger must belong to the same partition. If a trigger returns a Mutation containing more than one PartitionUpdate, TriggerExecutor.validateForSinglePartition throws this InvalidRequestException because a single-partition write cannot be extended with updates to other partitions atomically.","triggerScenarios":"A trigger's execute() returns a Mutation whose getPartitionUpdates() yields more than one PartitionUpdate (e.g. the trigger writes to multiple rows/tables), and the originating statement is a single-partition modification.","commonSituations":"Triggers written against multi-partition semantics being attached to single-row statements; a trigger writing to more than one table in one Mutation; misunderstanding the trigger contract that each augmented Mutation must target one partition for single-partition requests.","solutions":["Modify the trigger to return only a single PartitionUpdate per Mutation","Have the trigger return multiple Mutation objects, each targeting one partition, instead of one Mutation with several updates","Restrict the trigger to statements that are already multi-partition (e.g. batch), if the semantics allow"],"exampleFix":"// before (trigger code)\nreturn new Mutation(Arrays.asList(updateA, updateB)); // 2 partitions\n// after\nreturn Arrays.asList(new Mutation(updateA), new Mutation(updateB));","handlingStrategy":"try-catch","validationCode":"// in trigger code, before returning\nif (mutation.getPartitionUpdates().size() > 1) throw new IllegalArgumentException('Trigger must produce one partition update per Mutation');","typeGuard":null,"tryCatchPattern":"catch InvalidRequestException mentioning 'not all for the same partition' and fall back to application-level writes","preventionTips":["Keep each Mutation returned by a trigger limited to a single PartitionUpdate","Unit-test triggers against single-partition statements","Document trigger partition-key constraints in the trigger class"],"tags":["triggers","partition-update","invalid-request","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}