Skip to content

fix: BaseTask.get_id potentially returning None#5047

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-basetask-get-id-none
Open

fix: BaseTask.get_id potentially returning None#5047
Copilot wants to merge 4 commits intomainfrom
copilot/fix-basetask-get-id-none

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 2, 2026

BaseTask.get_id() silently returned None when no matching task was found in the workflow state, causing an obscure TypeError downstream in get_idx() when attempting to subscript the None result.

Context

get_id() iterated over workflow state without a fallback, returning None on a miss. Callers like get_idx() assumed a str return, producing:

TypeError: 'NoneType' object is not subscriptable

Change Summary

  • Added raise RuntimeError(...) at the end of BaseTask.get_id() to surface the failure at the source with a clear, actionable message including the task name:
    raise RuntimeError(
        f"Task ID not found for task '{self.name()}'. "
        "This may indicate the task was not properly initialized."
    )

Rationale

Failing fast with a descriptive error is preferable to propagating None and producing a confusing TypeError several 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 raise RuntimeError immediately instead of silently returning None. The return type contract (str) is now enforced at runtime.

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
2 tasks
@Gobot1234 Gobot1234 marked this pull request as ready for review April 2, 2026 13:22
Copilot AI review requested due to automatic review settings April 2, 2026 13:22
Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/7757a4b3-49ee-4d7e-9df4-6f8b2f8d9ac6

Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix BaseTask.get_id potentially returning None Fix BaseTask.get_id returning None when task ID not found Apr 2, 2026
Copilot AI requested a review from Gobot1234 April 2, 2026 13:23
@Gobot1234 Gobot1234 changed the title Fix BaseTask.get_id returning None when task ID not found fix: BaseTask.get_id potentially returning None Apr 2, 2026
@github-actions github-actions bot added the bug Issue, problem or error in PyFluent label Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RuntimeError in BaseTask.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(
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
type_, id_ = k.split(":")
if type_ == "TaskObject":
return id_
raise RuntimeError(
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@Gobot1234
Copy link
Copy Markdown
Collaborator

I don't think this really needs a test as it's covered by type checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue, problem or error in PyFluent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseTask.get_id potentially returning None

4 participants