Skip to content

Commit 7486e46

Browse files
nghuiqinfacebook-github-bot
authored andcommitted
Fix issue handling function with decorator (#1111)
Summary: Pull Request resolved: #1111 Add support to handle function with decorators that hit validation errors. **Root cause:** If the function contains decorators, the getabsfile will return the decorator function filepath. **Fix**: Add an unwrap before we getabsfile, this could lead to right filepath. Reviewed By: kiukchung Differential Revision: D82132556
1 parent 456bde8 commit 7486e46

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

torchx/specs/finder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ def _get_path_to_function_decl(
287287
my_component defined in some_file.py, imported in other_file.py
288288
and the component is invoked as other_file.py:my_component
289289
"""
290-
path_to_function_decl = inspect.getabsfile(function)
290+
# Unwrap decorated functions to get the original function
291+
unwrapped_function = inspect.unwrap(function)
292+
path_to_function_decl = inspect.getabsfile(unwrapped_function)
291293
if path_to_function_decl is None or not os.path.isfile(path_to_function_decl):
292294
return self._filepath
293295
return path_to_function_decl

0 commit comments

Comments
 (0)