diff --git a/dash/_utils.py b/dash/_utils.py index cd4638e0a9..45b9394944 100644 --- a/dash/_utils.py +++ b/dash/_utils.py @@ -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 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)