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

Fix get_caller_name #2672

merged 3 commits into from
Oct 26, 2023

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Oct 25, 2023

Fix get_caller_name by always taking the third stack frame from the function call. (0 is get_caller_name, __init__ is 1 then next one is the app = Dash() call)

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Oct 25, 2023

Taking by index doesn't work in the case of a custom dash class.

Think we can do with a check on the function name, it is get_caller then a chain of __init__ and we are looking for <module> which has a name.

dash/dash.py Outdated Show resolved Hide resolved
Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 This looks good to me!

Note that there's at least one case where this can give a different result from app = Dash(__name__): if you create app in a function that you call from a different module. The inferred root will be the last time you were at the module scope before calling a function. You could construct some very strange situations here - a function imports a module, and that module calls a function that creates the dash app... but it feels to me as though in all those situations you should really be passing in __name__ from the user code anyway, so what you have is the right solution.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Oct 26, 2023

but it feels to me as though in all those situations you should really be passing in name

Yes I think in those cases you would want to give what is appropriate by either passing the __name__ from the module or in a function argument.

@T4rk1n T4rk1n merged commit 2608674 into dev Oct 26, 2023
3 checks passed
@T4rk1n T4rk1n deleted the fix-get-name branch October 26, 2023 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants