-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG] Dash Pages does not support relative package imports within page modules #2263
Comments
I think I've tracked down a workaround... The problem is that within
So we need to get the package name reflected in the
I also had to make a similar change in the router so that the 404 page can be retrieved from the router, to match the module name structure now found in the registry. Not sure if this workaround will generalise to apps not defined in packages. I might have a go trying these changes against the test suite. |
So after running Dash's
Previously, the second would have overwritten the first, as they both would have resolved to @AnnMarieW do you have any other ideas for getting Dash Pages modules to play nice with relative imports inside a package? Or is it worth pursuing the line of thinking I was going down? |
ok I have a candidate solution to the above issues that I'd be keen to get your take on @T4rk1n @alexcjohnson, and @ann-marie-ward the problem with my solution of prefixing I've done some experimentation in this PR #2271 to see what happens when we clear the contents of
it looks like they are sensitive to dirty state hanging around from previous app inits. something that I think is a particular smell is that
I'm wondering if this also opens up a slightly larger question of whether all global Dash state should be reset on app init. beyond Dash pages, there's also the global state that the but for now, how do we feel about clearing |
Env:
Describe the bug
I typically make my Dash apps as Python packages, using relative imports within my app. I've just discovered that Dash Pages is not happy with relative imports being used within your page modules (eg
pages/page1.py
). As far as I can tell, this is because Dash manually loads the contents ofpages
as modules usingexec_module
, but, if your app is inside a package, it does not attach the page modules to the package. So when you try to access autils.py
in the base of your package, eg withfrom ..utils import blah
withinpages/page1.py
, you'll get:So effectively, every module within your
pages
directory is orphaned from the package, and you won't be able to use relative imports to share utility functions across your page modules and the rest of your app.Minimal example
__init__.py
(empty)app.py
pages/__init__.py
(empty)pages/page.py
utils.py
Runnning
python -m dash_pages_bug.app
from the directory above results in:The text was updated successfully, but these errors were encountered: