Skip to content

Commit 2608674

Browse files
authored
Merge pull request #2672 from plotly/fix-get-name
Fix get_caller_name
2 parents aa0473e + f7336a2 commit 2608674

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
7+
## Fixed
8+
9+
- [#2672](https://github.com/plotly/dash/pull/2672) Fix `get_caller_name` in case the source is not available.
10+
511
## [2.14.0] - 2023-10-11
612

713
## Fixed

dash/_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ def parse_version(version):
284284
return tuple(int(s) for s in version.split("."))
285285

286286

287-
def get_caller_name(name: str):
287+
def get_caller_name():
288288
stack = inspect.stack()
289289
for s in stack:
290-
for code in s.code_context:
291-
if f"{name}(" in code:
292-
return s.frame.f_locals.get("__name__", "__main__")
290+
if s.function == "<module>":
291+
return s.frame.f_locals.get("__name__", "__main__")
292+
293293
return "__main__"

dash/dash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def __init__( # pylint: disable=too-many-statements
396396
):
397397
_validate.check_obsolete(obsolete)
398398

399-
caller_name = get_caller_name(self.__class__.__name__)
399+
caller_name = None if name else get_caller_name()
400400

401401
# We have 3 cases: server is either True (we create the server), False
402402
# (defer server creation) or a Flask app instance (we use their server)

0 commit comments

Comments
 (0)