fix: op.function
doesn't work with slices.
#809
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the issues encountered when defining an
OP
usingOP.function
and utilizing theslices
feature, although it has not been thoroughly tested yet.dflow version: 1.8.67.
I have noticed that functions decorated with the
@OP.function
decorator raising an error withslices
, such as"TypeError: the type of <redacted> must be a list; got pathlib.PosixPath instead."
I have traced the issue to (notice Line515&518)
dflow/src/dflow/python/python_op_template.py
Lines 503 to 519 in 8c8c1b7
get_input_sign
of class method defined using a Python class, as it returns an actual dictionary returned by the class method, which is created when calling it. However, the behavior is different withinOP.function
due to some interesting things of Python functions. Methods defined within library class methods inpython_op_template.py
and those created within class methods defined in the__main__
scope do not behave consistently, leading to different behavior when executed within a container. If the OP is defined byOP.function
and attempts to use the slices feature, the Python interpreter alters the input type of the OP, whereinput_sign
will be changed because it is returned byget_input_sign
instead of a copy.I propose to protect it using deepcopy() in this PR, but I am not certain if there are any other implications.
P.S. for quick check the behavior in
render_script
:expect:
but: