Skip to content

Commit 6e91065

Browse files
committed
reworked hash change detection error messages
1 parent 509afc7 commit 6e91065

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

pydra/engine/core.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,8 @@ def result(self, state_index=None, return_inputs=False):
821821
822822
Returns
823823
-------
824-
result :
825-
824+
result : Result
825+
the result of the task
826826
"""
827827
# TODO: check if result is available in load_result and
828828
# return a future if not
@@ -894,27 +894,33 @@ def _check_for_hash_changes(self):
894894
details = ""
895895
for changed in hash_changes:
896896
field = getattr(attr.fields(type(self.inputs)), changed)
897+
val = getattr(self.inputs, changed)
898+
field_type = type(val)
897899
if issubclass(field.type, FileSet):
898900
details += (
899-
f"- '{changed}' field is of file-type {field.type}. If it "
900-
"is intended to contain output data then the type of the field in "
901-
"the interface class should be changed to `pathlib.Path`. Otherwise, "
902-
"if the field is intended to be an input field but it gets altered by "
903-
"the task in some way, then the 'copyfile' flag should be set to "
904-
"'copy' in the field metadata of the task interface class so copies of "
905-
"the files/directories in it are passed to the task instead\n"
901+
f"- {changed}: value passed to the {field.type} field is of type "
902+
f"{field_type} ('{val}'). If it is intended to contain output data "
903+
"then the type of the field in the interface class should be changed "
904+
"to `pathlib.Path`. Otherwise, if the field is intended to be an "
905+
"input field but it gets altered by the task in some way, then the "
906+
"'copyfile' flag should be set to 'copy' in the field metadata of "
907+
"the task interface class so copies of the files/directories in it "
908+
"are passed to the task instead.\n"
906909
)
907910
else:
908911
details += (
909-
f"- the {field.type} object passed to '{changed}' field appears to "
910-
f"have an unstable hash. The {field.type}.__bytes_repr__() method "
911-
"can be implemented to provide stable hashes for this type. "
912-
"See pydra/utils/hash.py for examples.\n"
912+
f"- {changed}: the {field_type} object passed to the {field.type}"
913+
f"field appears to have an unstable hash. This could be due to "
914+
"a stochastic/non-thread-safe attribute(s) of the object\n\n"
915+
f"The {field.type}.__bytes_repr__() method can be implemented to "
916+
"bespoke hashing methods based only on the stable attributes for "
917+
f"the `{field_type.__module__}.{field_type.__name__}` type. "
918+
f"See pydra/utils/hash.py for examples. Value: {val}\n"
913919
)
914920
if hash_changes:
915921
raise RuntimeError(
916922
f"Input field hashes have changed during the execution of the "
917-
f"'{self.name}' {type(self).__name__}.\n{details}"
923+
f"'{self.name}' {type(self).__name__}.\n\n{details}"
918924
)
919925
logger.debug(
920926
"Input values and hashes for '%s' %s node:\n%s\n%s",

pydra/engine/submitter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ async def expand_workflow(self, wf, rerun=False):
216216
"You may need to implement a specific `bytes_repr()` "
217217
'"singledispatch overload"s or `__bytes_repr__()` '
218218
"dunder methods to handle one or more types in "
219+
"your interface inputs."
219220
)
220221
raise RuntimeError(msg)
221222
for task in tasks:

pydra/utils/hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def hash_function(obj, cache=None):
6464
return hash_object(obj, cache=cache).hex()
6565

6666

67-
def hash_object(obj: object, cache=None) -> Hash:
67+
def hash_object(obj: object, cache: Cache | None = None) -> Hash:
6868
"""Hash an object
6969
7070
Constructs a byte string that uniquely identifies the object,

0 commit comments

Comments
 (0)