Skip to content

Commit d9568e9

Browse files
authored
Merge pull request #1727 from plotly/register-resource-fix
fixed bug causing 'dash_html_components.' to be imported instead of d…
2 parents 5647abe + bee7116 commit d9568e9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

dash/dash.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,10 @@ def _collect_and_register_resources(self, resources):
618618
# add the version number of the package as a query parameter
619619
# for cache busting
620620
def _relative_url_path(relative_package_path="", namespace=""):
621-
if any(x in relative_package_path for x in ["dcc", "html", "dash_table"]):
621+
if any(
622+
relative_package_path.startswith(x + "/")
623+
for x in ["dcc", "html", "dash_table"]
624+
):
622625
relative_package_path = relative_package_path.replace("dash.", "")
623626
version = importlib.import_module(
624627
"{}.{}".format(namespace, os.path.split(relative_package_path)[0])

tests/unit/test_resources.py

+20
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,23 @@ def test_internal(mocker):
102102
), "Dynamic resource not available in registered path {}".format(
103103
app.registered_paths["dash"]
104104
)
105+
106+
107+
def test_collect_and_register_resources(mocker):
108+
109+
app = dash.Dash(
110+
__name__, assets_folder="tests/assets", assets_ignore="load_after.+.js"
111+
)
112+
with mock.patch("dash.dash.os.stat", return_value=StatMock()):
113+
with mock.patch("dash.dash.importlib.import_module") as import_mock:
114+
with mock.patch("sys.modules", {"dash_html_components": dcc}):
115+
import_mock.return_value = dcc
116+
app._collect_and_register_resources(
117+
[
118+
{
119+
"namespace": "dash_html_components",
120+
"relative_package_path": "dash_html_components.min.js",
121+
},
122+
]
123+
)
124+
import_mock.assert_any_call("dash_html_components")

0 commit comments

Comments
 (0)