Skip to content

Commit 118b3c7

Browse files
authored
PortableRunner tests: surface worker-thread exceptions on main thread after wait_until_finish() (fixes #35211) (#36485)
* fix, yapf, pylintt, isort * portable-runner: re-raise worker errors in wait_until_finish * Revert fn_runner_test.py to origin/master
1 parent faae168 commit 118b3c7

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

sdks/python/apache_beam/runners/portability/local_job_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ def _run_job(self):
309309
message_text=traceback.format_exc()))
310310
_LOGGER.exception('Error running pipeline.')
311311
self.set_state(beam_job_api_pb2.JobState.FAILED)
312-
raise
313312

314313
def _invoke_runner(self):
315314
self.set_state(beam_job_api_pb2.JobState.RUNNING)

sdks/python/apache_beam/runners/portability/portable_runner.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,17 @@ def wait_until_finish(self, duration=None):
528528
the execution. If None or zero, will wait until the pipeline finishes.
529529
:return: The result of the pipeline, i.e. PipelineResult.
530530
"""
531+
last_error_text = None
532+
531533
def read_messages() -> None:
534+
nonlocal last_error_text
532535
previous_state = -1
533536
for message in self._message_stream:
534537
if message.HasField('message_response'):
535-
logging.log(
536-
MESSAGE_LOG_LEVELS[message.message_response.importance],
537-
"%s",
538-
message.message_response.message_text)
538+
mr = message.message_response
539+
logging.log(MESSAGE_LOG_LEVELS[mr.importance], "%s", mr.message_text)
540+
if mr.importance == beam_job_api_pb2.JobMessage.JOB_MESSAGE_ERROR:
541+
last_error_text = mr.message_text
539542
else:
540543
current_state = message.state_response.state
541544
if current_state != previous_state:
@@ -566,6 +569,9 @@ def read_messages() -> None:
566569

567570
if self._runtime_exception:
568571
raise self._runtime_exception
572+
from apache_beam.runners.runner import PipelineState
573+
if self._state == PipelineState.FAILED:
574+
raise RuntimeError(last_error_text or "Pipeline failed.")
569575

570576
return self._state
571577

0 commit comments

Comments
 (0)