Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
- Fix `plotly.utils.node_generator` skipping dictionaries nested inside lists, so figure comparison helpers now visit dictionaries in `data` and other list-valued properties.

## [7.2.0] - 2026-11-24

Expand Down
16 changes: 11 additions & 5 deletions plotly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,17 @@ def node_generator(node, path=()):
"""
if not isinstance(node, dict):
return # in case it's called with a non-dict node at top level
yield node, path
for key, val in node.items():
if isinstance(val, dict):
for item in node_generator(val, path + (key,)):
yield item

def _walk(value, current_path):
if isinstance(value, dict):
yield value, current_path
for key, val in value.items():
yield from _walk(val, current_path + (key,))
elif isinstance(value, (list, tuple)):
for index, item in enumerate(value):
yield from _walk(item, current_path + (index,))

yield from _walk(node, path)


def get_by_path(obj, path):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_core/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ def test_node_generator(self):
]
for i, item in enumerate(node_generator(node0)):
self.assertEqual(item, expected_node_path_tuples[i])

def test_node_generator_descends_into_lists(self):
marker = {"color": "red"}
trace = {"marker": marker}
node = {"data": [trace], "layout": {}}

self.assertEqual(
list(node_generator(node)),
[
(node, ()),
(trace, ("data", 0)),
(marker, ("data", 0, "marker")),
({}, ("layout",)),
],
)