barseghyanartur / graphene-elastic

Graphene Elasticsearch/OpenSearch (DSL) integration
https://pypi.org/project/graphene-elastic/
71 stars 18 forks source link

Nested search backends #61

Closed barseghyanartur closed 3 years ago

lingfromSh commented 3 years ago

@barseghyanartur I figured out why tests failed.


class BaseBackend:

    def __init__(self, args=None):
        self.args = args or {}

class BackendA(BaseBackend):
    ...

class BackendB(BaseBackend):
    ...

if __name__ == "__main__":

    data = {
        "key1": "value1",
        "key2": {
            "nested_key1": {},
            "nested_key2": "nested_value2"
        }
    }

    backend_a = BackendA(args=dict(data))
    backend_b = BackendB(args=dict(data))

    backend_a.args.update(key1="changed")   
    print(backend_b.args)   # {'key1': 'value1', 'key2': {'nested_key1': {}, 'nested_key2': 'nested_value2'}}

    backend_a.args['key2'].update(nested_key1="changed")
    print(backend_b.args)   # {'key1': 'value1', 'key2': {'nested_key1': 'changed', 'nested_key2': 'nested_value2'}}

    print(backend_a.args["key2"] is backend_b.args['key2'])  # True

When CompoundSearchFilterBackend and SearchFilterBackend both did pop operation on the same dict, the tests failed.