Skip to content

fix: deep-copy literal values so changes do not propagate across calls#359

Open
frankiethekneeman wants to merge 2 commits into
jmespath:developfrom
frankiethekneeman:fix/literal-cache-mutation
Open

fix: deep-copy literal values so changes do not propagate across calls#359
frankiethekneeman wants to merge 2 commits into
jmespath:developfrom
frankiethekneeman:fix/literal-cache-mutation

Conversation

@frankiethekneeman
Copy link
Copy Markdown

Summary

  • visit_literal was returning node['value'] directly — the same object stored in the cached AST
  • Mutating the returned list or dict would affect all subsequent searches using the same expression
  • Fix: return copy.deepcopy(node['value']) so callers always receive an independent copy

Test plan

  • 5 new tests in TestPythonSpecificCases covering empty list, list with values, nested dict, dict key addition, and dict key overwrite
  • All 5 tests confirmed failing before the fix (red), passing after (green)
  • Full suite: 996 passed, 1 skipped

Fixes #318.

…alls

Changes to a returned list or dict should not propagate to subsequent
searches using the same expression. These tests are expected to fail
until visit_literal returns a deep copy.
visit_literal was returning node['value'] directly — the same object
stored in the cached AST. Mutating the returned list or dict would
affect all subsequent searches using the same expression.

Fixes jmespath#318.
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.

Unexpected mutations when using list or object literals in expressions

1 participant