From ef54bcf267cd2b122876b749782c9e713a3944f1 Mon Sep 17 00:00:00 2001 From: Corebit <123189979+corebit-nl@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:57:09 +0000 Subject: [PATCH] Fallback on long callback function names if source cannot be found --- dash/long_callback/managers/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dash/long_callback/managers/__init__.py b/dash/long_callback/managers/__init__.py index 5bfdc837bc..f7986506c0 100644 --- a/dash/long_callback/managers/__init__.py +++ b/dash/long_callback/managers/__init__.py @@ -55,7 +55,11 @@ def get_updated_props(self, key): raise NotImplementedError def build_cache_key(self, fn, args, cache_args_to_ignore): - fn_source = inspect.getsource(fn) + try: + fn_source = inspect.getsource(fn) + fn_str = fn_source + except OSError: # pylint: disable=too-broad-exception + fn_str = getattr(fn, "__name__", "") if not isinstance(cache_args_to_ignore, (list, tuple)): cache_args_to_ignore = [cache_args_to_ignore] @@ -68,7 +72,7 @@ def build_cache_key(self, fn, args, cache_args_to_ignore): arg for i, arg in enumerate(args) if i not in cache_args_to_ignore ] - hash_dict = dict(args=args, fn_source=fn_source) + hash_dict = dict(args=args, fn_source=fn_str) if self.cache_by is not None: # Caching enabled