mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-23 18:13:28 +08:00
Fix to_hashable traversal stack handling
This commit is contained in:
parent
6158cd5820
commit
a6472b1514
@ -275,7 +275,8 @@ def to_hashable(obj, max_nodes=_MAX_SIGNATURE_CONTAINER_VISITS):
|
|||||||
snapshots = {}
|
snapshots = {}
|
||||||
sort_memo = {}
|
sort_memo = {}
|
||||||
processed = 0
|
processed = 0
|
||||||
stack = [(obj, False)]
|
# Keep traversal state separate from container snapshots/results.
|
||||||
|
work_stack = [(obj, False)]
|
||||||
|
|
||||||
def resolve_value(value):
|
def resolve_value(value):
|
||||||
"""Resolve a child value from the completed memo table when available."""
|
"""Resolve a child value from the completed memo table when available."""
|
||||||
@ -309,8 +310,8 @@ def to_hashable(obj, max_nodes=_MAX_SIGNATURE_CONTAINER_VISITS):
|
|||||||
|
|
||||||
return (container_tag, tuple(value for _, value in ordered_items))
|
return (container_tag, tuple(value for _, value in ordered_items))
|
||||||
|
|
||||||
while stack:
|
while work_stack:
|
||||||
current, expanded = stack.pop()
|
current, expanded = work_stack.pop()
|
||||||
current_type = type(current)
|
current_type = type(current)
|
||||||
|
|
||||||
if current_type in _PRIMITIVE_SIGNATURE_TYPES or current_type is Unhashable:
|
if current_type in _PRIMITIVE_SIGNATURE_TYPES or current_type is Unhashable:
|
||||||
@ -388,7 +389,7 @@ def to_hashable(obj, max_nodes=_MAX_SIGNATURE_CONTAINER_VISITS):
|
|||||||
return Unhashable()
|
return Unhashable()
|
||||||
|
|
||||||
active.add(current_id)
|
active.add(current_id)
|
||||||
stack.append((current, True))
|
work_stack.append((current, True))
|
||||||
if current_type is dict:
|
if current_type is dict:
|
||||||
try:
|
try:
|
||||||
items = list(current.items())
|
items = list(current.items())
|
||||||
@ -398,8 +399,8 @@ def to_hashable(obj, max_nodes=_MAX_SIGNATURE_CONTAINER_VISITS):
|
|||||||
active.discard(current_id)
|
active.discard(current_id)
|
||||||
continue
|
continue
|
||||||
for key, value in reversed(items):
|
for key, value in reversed(items):
|
||||||
stack.append((value, False))
|
work_stack.append((value, False))
|
||||||
stack.append((key, False))
|
work_stack.append((key, False))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
items = list(current)
|
items = list(current)
|
||||||
@ -409,7 +410,7 @@ def to_hashable(obj, max_nodes=_MAX_SIGNATURE_CONTAINER_VISITS):
|
|||||||
active.discard(current_id)
|
active.discard(current_id)
|
||||||
continue
|
continue
|
||||||
for item in reversed(items):
|
for item in reversed(items):
|
||||||
stack.append((item, False))
|
work_stack.append((item, False))
|
||||||
|
|
||||||
return memo.get(id(obj), Unhashable())
|
return memo.get(id(obj), Unhashable())
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,21 @@ def test_get_immediate_node_signature_canonicalizes_non_link_inputs(monkeypatch)
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_to_hashable_walks_dicts_without_rebinding_traversal_stack():
|
||||||
|
live_value = {
|
||||||
|
"outer": {"nested": [2, 3]},
|
||||||
|
"items": [{"leaf": 4}],
|
||||||
|
}
|
||||||
|
|
||||||
|
assert caching.to_hashable(live_value) == (
|
||||||
|
"dict",
|
||||||
|
(
|
||||||
|
("items", ("list", (("dict", (("leaf", 4),)),))),
|
||||||
|
("outer", ("dict", (("nested", ("list", (2, 3))),))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_immediate_node_signature_fails_closed_for_opaque_non_link_input(monkeypatch):
|
def test_get_immediate_node_signature_fails_closed_for_opaque_non_link_input(monkeypatch):
|
||||||
class OpaqueRuntimeValue:
|
class OpaqueRuntimeValue:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user