Skip to content

Commit

Permalink
Fix get_caller_name
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Oct 25, 2023
1 parent aa0473e commit a24feaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ def parse_version(version):
return tuple(int(s) for s in version.split("."))


def get_caller_name(name: str):
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__")
return "__main__"
def get_caller_name():
try:
stack = inspect.stack()
# takes the stack before the `__init__`
# 0 is current, __init__ is 1 then next one is the `app = Dash()` call
s = stack[2]
return s.frame.f_locals.get("__name__", "__main__")
finally:
return "__main__" # pylint: disable=lost-exception
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 = 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

0 comments on commit a24feaa

Please sign in to comment.