Skip to content

[BUG] The _module_name_is_package function in _pages.py is problematic #3309

Closed
@yaoyi92

Description

@yaoyi92

The _module_name_is_package function in dash/_pages.py is used to check whether a name is a package.

In the latest version (bb13521), the _module_name_is_package function reads

def _module_name_is_package(module_name):
    file_path = sys.modules[module_name].__file__
    return (
        file_path
        and module_name in sys.modules
        and Path(file_path).name == "__init__.py"
    )

This will crash if the module_name is not in sys.modules.

The original version (74252a8) of this function doesn't have this problem since the sys.modules won't be called if module_name is not in sys.modules.

def _module_name_is_package(module_name):
    return (
        module_name in sys.modules
        and Path(sys.modules[module_name].__file__).name == "__init__.py"
    )

Metadata

Metadata

Assignees

Labels

P1needed for current cyclebugsomething broken

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions