{"record":{"id":"f1b47677c9ac9c0c","repo":"apache/cassandra","slug":"table-of-additional-mutation-does-not-match-primar","errorCode":null,"errorMessage":"table of additional mutation does not match primary update table","messagePattern":"table of additional mutation does not match primary update table","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/triggers/TriggerExecutor.java","lineNumber":219,"sourceCode":"        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\n    {\n        if (!key.equals(update.partitionKey()))\n            throw new InvalidRequestException(\"Partition key of additional mutation does not match primary update key\");\n\n        if (!tableId.equals(update.metadata().id))\n            throw new InvalidRequestException(\"table of additional mutation does not match primary update table\");\n    }\n\n    private void validate(Collection<Mutation> tmutations) throws InvalidRequestException\n    {\n        for (Mutation mutation : tmutations)\n        {\n            QueryProcessor.validateKey(mutation.key().getKey());\n            for (PartitionUpdate update : mutation.getPartitionUpdates())\n                update.validate();\n        }\n    }\n\n    /**\n     * Switch class loader before using the triggers for the column family, if\n     * not loaded them with the custom class loader.\n     */\n    private List<Mutation> executeInternal(PartitionUpdate update)\n    {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/triggers/TriggerExecutor.java#L201-L237","documentation":"Along with the partition key, validateSamePartition checks that any PartitionUpdate produced by a trigger targets the same table (TableId) as the primary update. A mismatched table id means the trigger would write to a different table within a single-partition atomic modification, which is not permitted, so this InvalidRequestException is thrown.","triggerScenarios":"A trigger returns a PartitionUpdate whose metadata().id (table) differs from the TableId of the table being modified by the original statement.","commonSituations":"Triggers writing to a secondary/audit table defined alongside the primary table; trigger configured with a hardcoded table name that doesn't match the statement's table; trigger reused across multiple tables.","solutions":["Make the trigger write to the same table as the statement, or remove the trigger from tables where it cannot comply","Drop and recreate the trigger so it is only attached to the table it actually writes to","Move the write to the other table into application code"],"exampleFix":"// before (trigger code)\nPartitionUpdate up = PartitionUpdate.builder(auditTable, key).build();\n// after\nPartitionUpdate up = PartitionUpdate.builder(primaryTable, key).build();","handlingStrategy":"validation","validationCode":"// inside trigger: assert table id matches\nassert update.metadata().id.equals(tableId) : 'trigger update table mismatch';","typeGuard":null,"tryCatchPattern":"catch InvalidRequestException mentioning 'table of additional mutation does not match' and route the write elsewhere","preventionTips":["Only attach a trigger to the exact table it writes to","Query system_schema.triggers regularly to audit trigger/table pairing","Avoid hardcoded table names in trigger implementations"],"tags":["triggers","table-id","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"}