Skip to content

Commit 358a045

Browse files
authored
Fallback on background callback function names if source cannot be found
1 parent 30afe78 commit 358a045

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

dash/background_callback/managers/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def get_updated_props(self, key):
5656
raise NotImplementedError
5757

5858
def build_cache_key(self, fn, args, cache_args_to_ignore, triggered):
59-
fn_source = inspect.getsource(fn)
59+
try:
60+
fn_source = inspect.getsource(fn)
61+
fn_str = fn_source
62+
except OSError: # pylint: disable=too-broad-exception
63+
fn_str = getattr(fn, "__name__", "")
6064

6165
if not isinstance(cache_args_to_ignore, (list, tuple)):
6266
cache_args_to_ignore = [cache_args_to_ignore]
@@ -69,7 +73,7 @@ def build_cache_key(self, fn, args, cache_args_to_ignore, triggered):
6973
arg for i, arg in enumerate(args) if i not in cache_args_to_ignore
7074
]
7175

72-
hash_dict = dict(args=args, fn_source=fn_source, triggered=triggered)
76+
hash_dict = dict(args=args, fn_source=fn_str, triggered=triggered)
7377

7478
if self.cache_by is not None:
7579
# Caching enabled

0 commit comments

Comments
 (0)