I have the following python module:
paths = {}
...
def execute_query(query_to_execute, *args, **kwargs):
if 'paths' in kwargs:
paths = kwargs['paths']
queries = {
'postgresqlVersion': '''{{postgresqlVersion}}''',
'entityRelationships': '''{{entityRelationships (entity: "{}") {{name}}}}''',
'path': '''{{path(name: "{}", path: "{}", annotate: "{}")}}''',
'path_step': '''{{pathStep(name: "{}", step: "{}", key: {})}}'''
}
schema = graphene.Schema(query=Query)
#schema.execute('''{path(name: "Ventas", path: "general_state/general_city/inventory_store/operations_sale", annotate: "_count")}''')
result = schema.execute(queries[query_to_execute].format(*list(kwargs.values())))
dict_result = dict(result.data.items())
return {'top': dict_result, 'full': paths}
The problem is that the code only works if I remove the first two lines of method execute_query()
. If I leave them, I get this error:
File "/Users/hugovillalobos/Documents/Code/agrowareproject/backend/query.py", line 236, in execute_query
return {'top': dict_result, 'full': paths}
UnboundLocalError: local variable 'paths' referenced before assignment
I don't know why python does not recognize variable paths
as the one declared in the first line of the module.