Skip to content

Treat dict and list subclasses as groupings in flatten_grouping - #4240

Open
shaurya703 wants to merge 2 commits into
plotly:devfrom
shaurya703:fix/flatten-grouping-dict-subclass
Open

shaurya703 wants to merge 2 commits into
plotly:devfrom
shaurya703:fix/flatten-grouping-dict-subclass

Conversation

@shaurya703

@shaurya703 shaurya703 commented Dec 4, 2026 •

Copy link
Copy Markdown

Since #3303 (3.1.0), flatten_grouping checks type(sch) is dict and type(sch) is tuple or type(sch) is list instead of isinstance. A dict subclass such as OrderedDict is no longer treated as a grouping. It comes back as one scalar value:

from collections import OrderedDict
from dash._grouping import flatten_grouping, grouping_len

flatten_grouping({"a": 1, "b": 2})               # [1, 2]
flatten_grouping(OrderedDict(a=1, b=2))          # [OrderedDict(...)], expected [1, 2]
grouping_len(OrderedDict(a=1, b=2))              # 2

grouping_len, validate_grouping, make_grouping_by_index and map_grouping in the same module still use isinstance, so they disagree with flatten_grouping about the same value. In a callback this shows up as a misleading error:

app.callback(
    output=OrderedDict(x=Output("b", "children")),
    inputs=OrderedDict(y=Input("a", "children")),
)
# ValueError: Invalid value provided where an Output dependency object was expected:
# OrderedDict({'x': <Output `b.children`>})

The same callback works today with a plain dict. It also works with an OrderedDict if dash/_grouping.py is put back to its version from before #3303: both new tests below pass against that version.

Fix: go back to isinstance(sch, (tuple, list)) and isinstance(sch, dict) and keep the rest of the stack-based loop from #3303 as it is.

Contributor Checklist

  • This PR targets dev (fix)
  • I have run the tests locally and they passed.
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
    • test_flatten_dict_subclass in tests/unit/library/test_grouping.py
    • test_callback_output_and_input_dict_subclass in tests/unit/library/test_grouped_callbacks.py, which registers and calls a callback with OrderedDict output and inputs

Both new tests fail on dev and pass with the change.

optionals

  • I have added entry in the CHANGELOG.md

Checks run locally: pytest tests/unit (777 passed, 7 skipped), black --check and flake8 on dash and tests (clean), and pylint dash setup.py --rcfile=.pylintrc, which reports only existing not-callable warnings in dash/testing/browser.py and diskcache_manager.py. I ran these with component bundles taken from the 4.5.2 wheel instead of an npm run build, and I did not run the renderer or integration tests. The change is Python-only.

flatten_grouping compared exact types (type(x) is dict) since plotly#3303, so an
OrderedDict or other dict subclass was returned as one scalar value. The
rest of the module uses isinstance, so grouping_len and flatten_grouping
disagreed on the same grouping, and a callback registered with an
OrderedDict output or inputs failed with "Invalid value provided where an
Output dependency object was expected".
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant