Fix #2941: make aws-ddb-sink honour its own operation property - #2992
Merged
Conversation
The Kamelet declared an inbound data type default:
dataTypes:
in:
default: json
which makes Camel apply the aws2-ddb:application-json transformation at
the kamelet:source boundary, before any template step runs. So by the time
"setProperty operation" executed, the transformer had already resolved the
operation from the body alone, defaulted to PutItem and stamped
CamelAwsDdbOperation. That header then beat the endpoint's
operation={{operation}} parameter in Ddb2Producer, leaving the Kamelet's
operation property with no effect.
The in-template transformDataType step was a no-op as a result: the
transformer returns early once CamelAwsDdbItem or CamelAwsDdbKey is set.
Dropping only the "default:" key stops the transformation happening at the
boundary and lets the existing transformDataType step apply it after the
operation is set. All of the declared input-type documentation -- schema,
header docs, description -- is preserved.
Probed each operation with `camel run`, replacing the terminal aws2-ddb
endpoint with a log so the resolved headers are visible:
PutItem CamelAwsDdbItem + ALL_OLD
DeleteItem CamelAwsDdbKey + ALL_OLD
UpdateItem CamelAwsDdbKey + CamelAwsDdbUpdateValues + ALL_NEW
Before the change UpdateItem produced the PutItem shape.
The itest route carried a workaround that set the operation exchange
property in the calling route; it is removed here, so the test now
exercises the Kamelet's own property. AwsIT passes end to end against
DynamoDB: 15 tests, 0 failures, all four ddb cases green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2941.
The issue suspected this might need a runtime fix in
apache/camel. It does not — the cause is in the Kamelet, and it is a two-character-shaped fix.Root cause
aws-ddb-sinkdeclared an inbound data type default:Declaring a default input type makes Camel apply that transformation at the
kamelet:sourceboundary — before any step in the template runs. Verified by logging the headers as the very first step of the template:The message is already transformed on arrival. Two consequences:
setProperty operationran after the transformer had already resolved the operation from the body alone and defaulted toPutItem. A log placed between the two showed${exchangeProperty.operation}=UpdateItemwhile the transform had already happened — which is why this looked so puzzling.CamelAwsDdbOperation, and inDdb2Producerthat header beats the endpoint'soperation={{operation}}parameter. So the Kamelet'soperationproperty could never take effect.The in-template
transformDataTypestep was dead code as a result —Ddb2JsonDataTypeTransformerreturns early onceCamelAwsDdbItemorCamelAwsDdbKeyis present.This also explains the reported workaround exactly: setting the exchange property in the calling route works because it is on the exchange before the boundary transformation.
Fix
Drop only the
default:key. The transformation then happens at the existingtransformDataTypestep, after the operation is set.dataTypes: in: - default: json types:All the declared input-type documentation — schema,
CamelAwsDdbOperation/CamelAwsDdbReturnValuesheader docs, description — is preserved. I deliberately did not remove the wholedataTypesblock (which also works) because that metadata is worth keeping.Verification
Probed each operation with
camel run, swapping the terminalaws2-ddbendpoint for alogso the resolved headers are visible:PutItemCamelAwsDdbItem+ALL_OLDDeleteItemCamelAwsDdbKey+ALL_OLDUpdateItemCamelAwsDdbKey+CamelAwsDdbUpdateValues+ALL_NEWBefore the change
UpdateItemproduced thePutItemshape —CamelAwsDdbItem+ALL_OLD— which is the reported bug.The itest workaround is removed.
aws-ddb-sink-route.yamlset theoperationexchange property in the calling route; that is deleted here, so the test now exercises the Kamelet's ownoperationproperty rather than the workaround.AwsITpasses end to end against DynamoDB:Run with
CITRUS_CAMEL_CLI_KAMELETS_LOCAL_DIRpointed at this working tree, since without #2987 the itests resolve the released catalog and would not have exercised this change at all.script/validatorreports no errors andmvn clean installpasses from the repository root.Note for reviewers
Two other Kamelets declare
dataTypesand carry an in-templatetransformDataType—aws-ddb-streams-sourceandgoogle-sheets-sink. That combination is what produced this bug here. I have not touched them: a source'soutdata type is a different code path and neither has a reported defect, so they are worth a look separately rather than a speculative change in this PR.Claude Code on behalf of Andrea Cosentino