Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/5049.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_AllowedSurfaceIDs.__call__ silently returning None on malformed surface info
21 changes: 14 additions & 7 deletions src/ansys/fluent/core/field_data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,20 @@ def valid_name(self, surface_name: str) -> str:

class _AllowedSurfaceIDs(_AllowedNames):
def __call__(self, respect_data_valid: bool = True) -> List[int]:
try:
return [
info["surface_id"][0]
for _, info in self._field_info._get_surfaces_info().items()
]
except (KeyError, IndexError):
pass
surface_info = self._field_info._get_surfaces_info()
Comment thread
Gobot1234 marked this conversation as resolved.
surface_ids = []
for surface_name, info in surface_info.items():
try:
surface_ids.append(info["surface_id"][0])

@mkundu1 mkundu1 Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If a user faces the below KeyError and IndexError, they will not know how to fix that error by reading the error-message. The key and the index are hardcoded values in the code, those are not supplied by the user.

Is there a real scenario where these errors can happen due to some user error? If the errors are due to some implementation logic (either in server or client), then that should be handled in the code without raising user-facing errors.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No I don't think there are I'm pretty sure you'd only hit this in an implementation failure. How would you handle this in the code in this case?

@mkundu1 mkundu1 Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we can ignore the missing key/index, we can simply return an empty list.

If we cannot ignore the missing key/index, that means an implementation issue. In that case we can do a debug-log for now and return an empty list. Ideally, the implementation should be fixed.

@prmukherj Please guide which of the above scenarios is the case here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Gobot1234, you are right that this issue can happen only due to an implementation problem. You can follow @mkundu1's first suggestion as this was just an extra precautionary check. Let's re-run the tests and check for test failures after this change and decide.
Thank you.

except KeyError:
raise LookupError(
f"Failed to retrieve valid surface_id key for surface '{surface_name}'."
)
except IndexError:
raise LookupError(
f"Failed to retrieve valid surface_id index for surface '{surface_name}'."
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
)
return surface_ids


class FieldUnavailable(RuntimeError):
Expand Down
39 changes: 39 additions & 0 deletions tests/test_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
from ansys.fluent.core.exceptions import DisallowedValuesError
from ansys.fluent.core.field_data_interfaces import (
FieldUnavailable,
_AllowedSurfaceIDs,
_Fields,
_SurfaceIds,
)
from ansys.fluent.core.services.field_data import (
CellElementType,
Expand Down Expand Up @@ -1017,3 +1019,40 @@ def test_field_data_objects_3d_with_location_objects_overall(
assert path_lines_data["hot-inlet"].scalar_field_name == "velocity-magnitude"

assert list(path_lines_data["cold-inlet"].lines[100]) == [100, 101]


def test_allowed_surface_ids_raises_on_missing_surface_id_key() -> None:
"""_AllowedSurfaceIDs.__call__ should raise LookupError when surface_id key is missing."""

class _FakeFieldInfo:
def _get_surfaces_info(self):
return {"bad-surface": {"no_surface_id_key": []}}

allowed = _AllowedSurfaceIDs(field_info=_FakeFieldInfo())
with pytest.raises(LookupError, match="surface_id key"):
allowed()


def test_allowed_surface_ids_raises_on_empty_surface_id_list() -> None:
"""_AllowedSurfaceIDs.__call__ should raise LookupError when surface_id list is empty."""

class _FakeFieldInfo:
def _get_surfaces_info(self):
return {"bad-surface": {"surface_id": []}}

allowed = _AllowedSurfaceIDs(field_info=_FakeFieldInfo())
with pytest.raises(LookupError, match="surface_id index"):
allowed()


def test_surface_ids_validate_raises_on_bad_surface_info() -> None:
"""_SurfaceIds.validate should propagate LookupError when surface info is malformed."""

class _FakeFieldInfo:
def _get_surfaces_info(self):
return {"bad-surface": {"surface_id": []}}

allowed = _AllowedSurfaceIDs(field_info=_FakeFieldInfo())
validator = _SurfaceIds(allowed)
with pytest.raises(LookupError, match="surface_id index"):
validator.validate([1])
Loading