fix: BaseTask.get_id potentially returning None#5047
Conversation
Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/7757a4b3-49ee-4d7e-9df4-6f8b2f8d9ac6 Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/7757a4b3-49ee-4d7e-9df4-6f8b2f8d9ac6 Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR prevents BaseTask.get_id() from implicitly returning None when the workflow state cannot be matched to the current task, avoiding downstream TypeErrors and making the failure explicit.
Changes:
- Add a terminal
RuntimeErrorinBaseTask.get_id()when no task ID can be resolved from the workflow state.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type_, id_ = k.split(":") | ||
| if type_ == "TaskObject": | ||
| return id_ | ||
| raise RuntimeError( |
There was a problem hiding this comment.
The new RuntimeError message ('Task ID not found, should be unreachable') is likely to surface in real user scenarios (e.g., partially initialized workflow) and isn’t actionable. Consider including the task name (and possibly the expected key prefix 'TaskObject:' / hint about initialization) so users can diagnose which task failed and why.
| type_, id_ = k.split(":") | ||
| if type_ == "TaskObject": | ||
| return id_ | ||
| raise RuntimeError( |
There was a problem hiding this comment.
This change introduces a new failure mode (raising when the task ID can’t be resolved) but there’s no test asserting the exception behavior. Adding a focused unit test that constructs a BaseTask with a stubbed/empty workflow state and verifies RuntimeError would prevent regressions and clarify the intended contract.
Up to standards ✅🟢 Issues
|
|
I don't think this really needs a test as it's covered by type checking |
BaseTask.get_id()silently returnedNonewhen no matching task was found in the workflow state, causing an obscureTypeErrordownstream inget_idx()when attempting to subscript theNoneresult.Context
get_id()iterated over workflow state without a fallback, returningNoneon a miss. Callers likeget_idx()assumed astrreturn, producing:Change Summary
raise RuntimeError(...)at the end ofBaseTask.get_id()to surface the failure at the source with a clear, actionable message including the task name:Rationale
Failing fast with a descriptive error is preferable to propagating
Noneand producing a confusingTypeErrorseveral call frames away. Including the task name in the message aids debugging without requiring a stack trace inspection.Impact
Any code path that reaches
get_id()with a task not present in the workflow state will now raiseRuntimeErrorimmediately instead of silently returningNone. The return type contract (str) is now enforced at runtime.