Skip to content

fix: safely parse task state and execution info in get_task_status#145

Merged
cdc-as81 merged 1 commit intorr-142-task-statusfrom
cdc-as81-task-status
Mar 26, 2026
Merged

fix: safely parse task state and execution info in get_task_status#145
cdc-as81 merged 1 commit intorr-142-task-statusfrom
cdc-as81-task-status

Conversation

@cdc-as81
Copy link
Copy Markdown
Collaborator

Fix task status parsing for pre-execution tasks

Motivation

This PR fixes a bug where get_task_status() crashes when encountering Azure Batch tasks that have not yet started executing or that return string-based states rather than enums.

Changes Made

  • Safe State Parsing: Used getattr() to safely extract the state value, falling back to string conversion to handle cases where the Azure SDK returns a plain string rather than a TaskState enum.
  • Safe Execution Info Parsing: Used getattr() to conditionally retrieve task.execution_info.exit_code, defaulting to None. This prevents AttributeError crashes for tasks in pre-run states (like active) that lack execution metadata entirely.
  • Test Coverage: Added a mock task with an active string state and unpopulated (None) execution_info to test_get_task_status_all_tasks() to guarantee these edge cases are exercised.

Use getattr to handle missing execution_info for active tasks
Safely fallback to string parsing when task.state is not an Enum
Add tests for string-based pre-execution task states
@cdc-as81 cdc-as81 requested a review from ryanraaschCDC March 26, 2026 19:04
@cdc-as81 cdc-as81 merged commit 24e9b48 into rr-142-task-status Mar 26, 2026
3 checks passed
@cdc-as81 cdc-as81 deleted the cdc-as81-task-status branch March 26, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants