Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected mutations when using list or object literals in expressions #318

Open
bwright1558 opened this issue Oct 19, 2023 · 0 comments
Open

Comments

@bwright1558
Copy link

bwright1558 commented Oct 19, 2023

Example code:

import jmespath


data = {}
my_list = jmespath.search('`[]`', data)
my_list.extend([1, 2, 3])
print(my_list)

new_data = {}
new_list = jmespath.search('`[]`', new_data)
new_list.extend([9, 8, 7])
print(new_list)

Expected Output:

[1, 2, 3]
[9, 8, 7]

Actual Output:

[1, 2, 3]
[1, 2, 3, 9, 8, 7]

The expression is getting cached as well as a reference to the empty list literal. This is causing unexpected mutations to other lists that should not be getting mutated.

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

No branches or pull requests

1 participant