Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/4729.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Block inactive object access via builtin classes.
11 changes: 9 additions & 2 deletions src/ansys/fluent/core/solver/settings_builtin_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

from typing import Protocol, runtime_checkable

from ansys.fluent.core.solver.flobject import NamedObject, SettingsBase
from ansys.fluent.core.solver.flobject import (
InactiveObjectError,
NamedObject,
SettingsBase,
)
from ansys.fluent.core.solver.settings_builtin_data import DATA
from ansys.fluent.core.utils.context_managers import _get_active_session
from ansys.fluent.core.utils.fluent_version import FluentVersion
Expand Down Expand Up @@ -68,7 +72,10 @@ def _get_settings_obj(settings_root, builtin_settings_obj):
found_path = path
comps = found_path.split(".")
for i, comp in enumerate(comps):
obj = SettingsBase.__getattribute__(obj, comp) # bypass InactiveObjectError
try:
obj = getattr(obj, comp)
except InactiveObjectError:
raise InactiveObjectError(builtin_cls_db_name) from None
if i < len(comps) - 1 and isinstance(obj, NamedObject):
obj_name = getattr(builtin_settings_obj, comp)
obj = obj[obj_name]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_builtin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import ansys.fluent.core as pyfluent
from ansys.fluent.core.examples import download_file
from ansys.fluent.core.solver import * # noqa: F401, F403
from ansys.fluent.core.solver.flobject import InactiveObjectError
from ansys.fluent.core.utils.fluent_version import FluentVersion

# flake8: noqa: F405
Expand Down Expand Up @@ -510,3 +511,11 @@ def test_context_manager_2(new_solver_session):
with using(solver):
read_case(file_name=import_filename)
assert Viscous().model() == "k-omega"


@pytest.mark.codegen_required
def test_inactive_objects(new_solver_session):
solver = new_solver_session

with pytest.raises(InactiveObjectError):
pyfluent.solver.Viscous(solver)