Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [UNRELEASED]

### Fixed
- [#4218](https://github.com/plotly/dash/pull/4218) Fix `pages_folder` written with `/` on Windows, such as `"src/pages"`, giving wrong page module names and paths. Fixes [#4217](https://github.com/plotly/dash/issues/4217).
- [#4220](https://github.com/plotly/dash/pull/4220) Fix the `DASH_VALIDATE_CALLBACKS` environment variable being ignored, although `Dash.run` and `Dash.enable_dev_tools` document it for `dev_tools_validate_callbacks`. Fixes [#4219](https://github.com/plotly/dash/issues/4219).

## [4.5.2] - 2026-11-27
Expand Down
6 changes: 5 additions & 1 deletion dash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def _module_name_is_package(module_name):


def _path_to_module_name(path):
return str(path).replace(".py", "").strip(os.sep).replace(os.sep, ".")
path = str(path)
if os.altsep:
# On Windows a folder given as "app/pages" mixes "/" with "\\"
path = path.replace(os.altsep, os.sep)
return path.replace(".py", "").strip(os.sep).replace(os.sep, ".")


def _infer_module_name(page_path):
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/pages/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pytest
Expand Down Expand Up @@ -62,6 +63,21 @@ def test_path_to_module_name(path, expected):
assert _pages._path_to_module_name(path) == expected


@pytest.mark.parametrize(
"path, expected",
[
(r"\sub_dir/custom_pages", "sub_dir.custom_pages"),
(r"\src/pages\home.py", "src.pages.home"),
(r"\sub_dir\custom_pages", "sub_dir.custom_pages"),
],
)
def test_path_to_module_name_windows_mixed_separators(monkeypatch, path, expected):
# a pages_folder written as "src/pages" on Windows mixes "/" and "\\"
monkeypatch.setattr(os, "sep", "\\")
monkeypatch.setattr(os, "altsep", "/")
assert _pages._path_to_module_name(path) == expected


@pytest.mark.parametrize(
"name, pages_folder, expected_module_name",
[
Expand Down
Loading