Skip to content

Compare dict keys starting with "__" in snapshots - #33

Merged
bentsku merged 1 commit into
mainfrom
aws-2688-localstack-snapshot-keys-starting-with-__-are-never-compared
Nov 4, 2026
Merged

bentsku merged 1 commit into
mainfrom
aws-2688-localstack-snapshot-keys-starting-with-__-are-never-compared

Conversation

@bentsku

@bentsku bentsku commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

SnapshotMatchResult compares recorded and observed state with DeepDiff, which defaults to ignore_private_variables=True. That setting also skips dict keys starting with __, so any value under such a key was never verified, and snapshot tests passed whatever the response contained there:

DeepDiff({"__schema": 1}, {"__schema": 2})                                  # {} -> "match"
DeepDiff({"__schema": 1}, {"__schema": 2}, ignore_private_variables=False)  # diff

Affected keys include __type (the error type in AWS JSON-protocol error responses) and GraphQL __typename / __schema. This came up in AppSync, where an introspection response under data.__schema differed from the AWS recording but the test still passed.

Tracked in AWS-2688.

Changes

  • Pass ignore_private_variables=False to DeepDiff in SnapshotMatchResult.
  • Add tests: __ key mismatches fail (top-level, nested, inside list items), equal __ keys pass, and skip_verification_paths such as $..__type still skip them. The four mismatch tests fail without the fix.

match_object is unaffected: it drops keys starting with _ itself before diffing.

Impact on consumers

Snapshot tests whose __ keys differ from the recording will now fail. Each one is a parity difference that was previously hidden. Fix the provider, add a transformer, or skip the path, e.g. @markers.snapshot.skip_snapshot_verify(paths=["$..__type"]).

🤖 Generated with Claude Code

DeepDiff defaults to ignore_private_variables=True, which also skips dict
keys starting with "__". Values under keys like "__type" (AWS JSON error
type) or GraphQL "__typename" / "__schema" were never verified against
the recording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku
bentsku added this pull request to stack #35 November 4, 2026 00:13
@bentsku bentsku mentioned this pull request Nov 4, 2026
@bentsku
bentsku marked this pull request as ready for review November 4, 2026 19:39
@bentsku
bentsku merged commit f42d48b into main Nov 4, 2026
4 checks passed
@bentsku
bentsku deleted the aws-2688-localstack-snapshot-keys-starting-with-__-are-never-compared branch November 4, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant