From c97c622a667a9c9e036fbee66d4e46a549cde051 Mon Sep 17 00:00:00 2001 From: philippe Date: Wed, 25 Oct 2023 15:15:53 -0400 Subject: [PATCH 1/3] Fix get_caller_name --- dash/_utils.py | 8 ++++---- dash/dash.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dash/_utils.py b/dash/_utils.py index cd4638e0a9..5b3b1d62e1 100644 --- a/dash/_utils.py +++ b/dash/_utils.py @@ -284,10 +284,10 @@ def parse_version(version): return tuple(int(s) for s in version.split(".")) -def get_caller_name(name: str): +def get_caller_name(): stack = inspect.stack() for s in stack: - for code in s.code_context: - if f"{name}(" in code: - return s.frame.f_locals.get("__name__", "__main__") + if s.function == "": + return s.frame.f_locals.get("__name__", "__main__") + return "__main__" diff --git a/dash/dash.py b/dash/dash.py index 7c0e38487c..6e5c88e964 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -396,7 +396,7 @@ def __init__( # pylint: disable=too-many-statements ): _validate.check_obsolete(obsolete) - caller_name = get_caller_name(self.__class__.__name__) + caller_name = get_caller_name() # We have 3 cases: server is either True (we create the server), False # (defer server creation) or a Flask app instance (we use their server) From 759ad6ba69c66a6416a4a0dd86549f0c3f9133f4 Mon Sep 17 00:00:00 2001 From: Philippe Duval Date: Wed, 25 Oct 2023 16:26:57 -0400 Subject: [PATCH 2/3] Update dash/dash.py Co-authored-by: Alex Johnson --- dash/dash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 6e5c88e964..08b5ea34c3 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -396,7 +396,7 @@ def __init__( # pylint: disable=too-many-statements ): _validate.check_obsolete(obsolete) - caller_name = get_caller_name() + caller_name = None if name else get_caller_name() # We have 3 cases: server is either True (we create the server), False # (defer server creation) or a Flask app instance (we use their server) From f7336a25e511607395bca0f17d842b865387365d Mon Sep 17 00:00:00 2001 From: philippe Date: Wed, 25 Oct 2023 16:53:21 -0400 Subject: [PATCH 3/3] Update changelog. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bddbaa0dbd..558dec5ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [UNRELEASED] + +## Fixed + +- [#2672](https://github.com/plotly/dash/pull/2672) Fix `get_caller_name` in case the source is not available. + ## [2.14.0] - 2023-10-11 ## Fixed