Skip to content

fix: BaseTask.get_id potentially returning None#5047

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

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

Conversation

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ansys/fluent/core/workflow.py
Comment thread src/ansys/fluent/core/workflow.py
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Gobot1234
Copy link
Copy Markdown
Collaborator

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

@Gobot1234 Gobot1234 enabled auto-merge (squash) April 21, 2026 12:43
Copilot AI review requested due to automatic review settings April 23, 2026 15:21
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ansys/fluent/core/workflow.py Outdated
Comment on lines 328 to 330
# pylint: disable=missing-raises-doc
def get_id(self) -> str:
"""Get the unique string identifier of this task, as it is in the application.
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The # pylint: disable=missing-raises-doc directive here will apply beyond get_id() (until re-enabled), which can unintentionally suppress missing-raises-doc warnings for the rest of this large module. Prefer documenting the new RuntimeError in the docstring with a Raises section and removing the disable; if a disable is still needed, scope it to just this function and re-enable immediately after.

Copilot uses AI. Check for mistakes.
Comment thread src/ansys/fluent/core/workflow.py Outdated

def get_id(self) -> str:
# pylint: disable=missing-raises-doc
def get_id(self) -> str:
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace after the function signature (def get_id(self) -> str:), which will typically trigger linting (e.g., W291). Please remove the extra spaces.

Suggested change
def get_id(self) -> str:
def get_id(self) -> str:

Copilot uses AI. Check for mistakes.
Comment on lines +344 to +347
raise RuntimeError(
f"Task ID not found for task '{self.name()}'. "
"This may indicate the task was not properly initialized."
)
Copy link

Copilot AI Apr 23, 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 error path (raising RuntimeError when the task name is missing from workflow state). Please add/adjust a test to assert this behavior so regressions don’t reintroduce the previous implicit None return (and downstream TypeError).

Copilot uses AI. Check for mistakes.
Comment thread src/ansys/fluent/core/workflow.py Outdated
Copilot AI review requested due to automatic review settings April 23, 2026 15:34
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/ansys/fluent/core/workflow.py:335

  • get_id() now raises, but the docstring still only documents Returns and the linter is suppressed with # pylint: disable=missing-raises-doc. Prefer documenting the new exception with a Raises section (consistent with other methods in this file) and removing the pylint suppression so the docstring stays accurate going forward.
    def get_id(self) -> str:  # pylint: disable=missing-raises-doc
        """Get the unique string identifier of this task, as it is in the application.

        Returns
        -------
        str
            The string identifier.
        """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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