Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_caller_name #2672

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<module>":
return s.frame.f_locals.get("__name__", "__main__")

return "__main__"
2 changes: 1 addition & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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)
Expand Down