Skip to content

Commit b9a3717

Browse files
committed
Move variable definition outside if.
1 parent 7fd1b2a commit b9a3717

File tree

1 file changed

+7
-5
lines changed
  • stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database

1 file changed

+7
-5
lines changed

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ def remove_commands(commands: ESCommandSet, path: ElasticPath) -> None:
150150
path (ElasticPath): Path to value to be removed
151151
152152
"""
153+
commands.add(f"def {path.variable_name};")
153154
if isinstance(path.key, int):
154155
commands.add(
155156
f"if (ctx._source{path.es_nest} instanceof ArrayList)"
156-
f"{{def {path.variable_name} = ctx._source{path.es_nest}.remove({path.es_key});}} else "
157+
f"{{{path.variable_name} = ctx._source{path.es_nest}.remove({path.es_key});}} else "
157158
)
158159

159160
commands.add(
160-
f"def {path.variable_name} = ctx._source{path.es_nest}.remove('{path.key}');"
161+
f"{path.variable_name} = ctx._source{path.es_nest}.remove('{path.key}');"
161162
)
162163

163164

@@ -190,11 +191,12 @@ def add_commands(
190191
if isinstance(path.key, int):
191192
commands.add(
192193
f"if (ctx._source{path.es_nest} instanceof ArrayList)"
193-
f"{{ctx._source{path.es_nest}.{'add' if operation.op in ['add', 'move'] else 'set'}({path.es_key}, {value})}}"
194-
f" else "
194+
f"{{ctx._source{path.es_nest}.{'add' if operation.op in ['add', 'move'] else 'set'}({path.es_key}, {value});}}"
195+
f" else ctx._source{path.es_nest}['{path.es_key}'] = {value};"
195196
)
196197

197-
commands.add(f"ctx._source{path.es_path} = {value};")
198+
else:
199+
commands.add(f"ctx._source{path.es_path} = {value};")
198200

199201

200202
def test_commands(

0 commit comments

Comments
 (0)