plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.

Home Page:https://plotly.com/dash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] wrong sorting of registered pages by ordering

gothicVI opened this issue · comments

Describe your context
Please provide us your environment, so we can easily reproduce the issue.

dash                              2.10.2
dash-ag-grid                      2.1.0
dash-bootstrap-components         1.4.1
dash-core-components              2.0.0
dash-html-components              2.0.0
dash-table                        5.0.0

Describe the bug
Hi,

I have an app where I add pages via:

register_page(
    __name__,
    path='/xxx',
    order=n,
    name="yyy",
    title="zzz"
)

where everything works fine as long as I have only 10 pages, i.e., n = 0,...,9.

As soon as I add an eleventh page and n turns into a two digit number, the new pages is entered as the third one, i.e., the sorting becomes: 0, 1, 10, 2, ..., 9.
This can also be seen by printing the page_registry in the global layout where I generate the navigation bar.

The error is due to the string cast here: https://github.com/plotly/dash/blob/dev/dash/_pages.py#L361

A workaround is to replace the above line with

key=lambda i: (str(i.get("order", i["module"])).zfill(9), i["module"]),

which prepends the order integer return with zeros to ensure correct sorting.
It is a dirty workaround as it would brake again when we have more then 100000000 pages but who would do that...