Fix changed_variables in automation and script traces (#108788)

This commit is contained in:
Erik Montnemery 2024-01-24 19:12:45 +01:00 committed by GitHub
parent aa86d87a31
commit 909e58066d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -477,11 +477,12 @@ class _ScriptRun:
try: try:
handler = f"_async_{action}_step" handler = f"_async_{action}_step"
await getattr(self, handler)() await getattr(self, handler)()
trace_element.update_variables(self._variables)
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
self._handle_exception( self._handle_exception(
ex, continue_on_error, self._log_exceptions or log_exceptions ex, continue_on_error, self._log_exceptions or log_exceptions
) )
finally:
trace_element.update_variables(self._variables)
def _finish(self) -> None: def _finish(self) -> None:
self._script._runs.remove(self) # pylint: disable=protected-access self._script._runs.remove(self) # pylint: disable=protected-access

View File

@ -1337,14 +1337,13 @@ async def test_wait_continue_on_timeout(
result_wait = {"wait": {"trigger": None, "remaining": 0.0}} result_wait = {"wait": {"trigger": None, "remaining": 0.0}}
variable_wait = dict(result_wait) variable_wait = dict(result_wait)
expected_trace = { expected_trace = {
"0": [{"result": result_wait}], "0": [{"result": result_wait, "variables": variable_wait}],
} }
if continue_on_timeout is False: if continue_on_timeout is False:
expected_trace["0"][0]["result"]["timeout"] = True expected_trace["0"][0]["result"]["timeout"] = True
expected_trace["0"][0]["error"] = "" expected_trace["0"][0]["error"] = ""
expected_script_execution = "aborted" expected_script_execution = "aborted"
else: else:
expected_trace["0"][0]["variables"] = variable_wait
expected_trace["1"] = [{"result": {"event": "test_event", "event_data": {}}}] expected_trace["1"] = [{"result": {"event": "test_event", "event_data": {}}}]
expected_script_execution = "finished" expected_script_execution = "finished"
assert_action_trace(expected_trace, expected_script_execution) assert_action_trace(expected_trace, expected_script_execution)