ComfyUI/tests-unit/nodes_test
haoshu.gu 59c565adf3 Fix duplicate custom node import when cross-referenced
When one custom node imports another custom node (e.g., via 'import custom_nodes.other_node'),
the ComfyUI custom node loader would previously load the imported node twice:
1. First time: via the explicit import statement (module name: custom_nodes.other_node)
2. Second time: via the automatic custom node scanner (module name: custom_nodes/other_node)

This caused issues including:
- Module initialization code being executed twice
- Route handlers being registered multiple times
- Potential state inconsistencies and data loss

This fix adds a check before loading a custom node to detect if it's already loaded
in sys.modules under either the standard import name or the path-based name.
If already loaded, it reuses the existing module instead of re-executing it.

Benefits:
- Prevents duplicate initialization of custom nodes
- Allows custom nodes to safely import other custom nodes
- Improves performance by avoiding redundant module loading
- Maintains backward compatibility with existing custom nodes

Also includes linting fix: use lazy % formatting in logging functions.
2025-12-24 05:51:37 +08:00
..
test_duplicate_import.py Fix duplicate custom node import when cross-referenced 2025-12-24 05:51:37 +08:00