Encode DynamoDB empty list and empty map attributes - #39731
Open
PDGGK wants to merge 1 commit into
Open
Conversation
AttributeValueCoder.encode selected the L and M branches with a size
check:
} else if (value.l() != null && value.l().size() > 0) {
} else if (value.m() != null && value.m().size() > 0) {
DynamoDB allows an empty L and an empty M, so both guards fail for one,
nul() is null, and it reaches the terminal else and throws
CoderException("Unknown Type"). One empty list anywhere inside an item
makes the whole item unencodable, since MAP_ATTRIBUTE_CODER re-enters
this coder for every child.
hasL()/hasM() are the SDK's way of separating "unset" from "set but
empty", which is exactly the distinction the size check lost.
The ss/ns/bs guards look identical and are deliberately left alone:
DynamoDB rejects empty sets, so an empty one there is not a value worth
preserving.
The decode side already handles both -- case l: and case m: delegate to
ListCoder/MapCoder, which round-trip empties.
Five tests. Four fail today with CoderException("Unknown Type"): empty
L, empty M, and the two nested cases that show a whole item is lost
rather than one attribute. The fifth asserts an AttributeValue with no
type set is still rejected, so the terminal else keeps its job; it
passes both before and after.
Contributor
|
Assigning reviewers: R: @ahmedabu98 for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
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 #39730.
AttributeValueCoder.encodeselected the L and M branches with a size check, so a DynamoDB attribute holding an empty list or empty map fell through to the terminalelseand threwCoderException("Unknown Type").hasL()/hasM()are the SDK's way of separating "unset" from "set but empty", which is exactly the distinction the size check lost.The
ss/ns/bsguards look identical and are deliberately left alone. DynamoDB rejects empty sets, so an empty one there is not a value worth preserving — relaxing those would be wrong.Blast radius.
MAP_ATTRIBUTE_CODERre-enters this coder for every child, so one empty list nested anywhere inside an item makes the whole item unencodable, not just that attribute. That is the realistic production trigger and it is what two of the new tests cover.The decode side already handles both:
case l:andcase m:delegate toListCoder/MapCoder, which round-trip empties.Compatibility
Wire-compatible for every value the service can produce. I want to be precise rather than overclaim: the change is not a no-op for a malformed
AttributeValuethat sets two types at once —AttributeValue.builder().l(new ArrayList<>()).nul(true).build()currently encodes asnuland would now encode asl. AnAttributeValuecarries exactly one type, DynamoDB never emits such a value, and no ordinary builder usage produces one, but the claim is "every value the service can produce", not "every possible value".Tests
Five cases added to the existing
AttributeValueCoderTest, which is a plain in-process encode/decode round trip — no cluster, no AWS account, no localstack.Lround tripCoderException: Unknown TypeMround tripLnested in a mapMnested in a listAttributeValue.builder().build()still rejectedThe fifth is there so the fix cannot quietly turn "Unknown Type" into encoding nothing, and because it passes on both versions it also shows the other four are not trivially red.
Each round trip asserts
hasL()/hasM()on the decoded value in addition to equality, so a "decoded back as unset" regression would still be caught.spotlessCheck,checkstyleMainandcheckstyleTestpass, as does the rest of thedynamodbpackage.