Skip to content

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

Description

@bwright1558

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions