Skip to content

Commit 3c149bd

Browse files
authored
Fix bug 843531 - DPF: Access violation when DataSource is incorrectly constructed (#1139)
* Raise an error if data_sources is an argument of a data_sources * Update the exception * Update the PR: Add a unit test
1 parent f120d58 commit 3c149bd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
)
1919

2020
from ansys.dpf.core.check_version import version_requires
21-
21+
from ansys.grpc.dpf import data_sources_pb2
22+
from ansys.dpf.core import errors
2223

2324
class DataSources:
2425
"""Contains files with analysis results.
@@ -77,9 +78,12 @@ def __init__(self, result_path=None, data_sources=None, server=None):
7778
self._internal_obj = core_api.data_processing_duplicate_object_reference(
7879
data_sources
7980
)
80-
else:
81+
elif isinstance(data_sources, data_sources_pb2.DataSources) or isinstance(data_sources, int):
8182
# It should be a message (usually from a call to operator_getoutput_data_sources)
8283
self._internal_obj = data_sources
84+
else:
85+
self._internal_obj = None
86+
raise errors.DpfValueError("Data source must be gRPC data sources message type")
8387
else:
8488
if self._server.has_client():
8589
self._internal_obj = self._api.data_sources_new_on_client(self._server.client)

tests/test_datasources.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def test_print_data_sources(allkindofcomplexity, server_type):
6161

6262

6363
def test_data_sources_from_data_sources(allkindofcomplexity, server_type):
64+
with pytest.raises(ValueError) as e:
65+
data_sources_false = dpf.core.DataSources(data_sources="Wrong Input", server=server_type)
66+
assert "Data source must be gRPC data sources message type" in e
6467
data_sources = dpf.core.DataSources(server=server_type)
6568
data_sources2 = dpf.core.DataSources(data_sources=data_sources, server=server_type)
6669

0 commit comments

Comments
 (0)