Skip to content

Fix V3 node subclasses inheriting the parent's cached schema values - #16205

Open
L4XB wants to merge 1 commit into
Comfy-Org:masterfrom
L4XB:fix/v3-subclass-schema-cache
Open

Fix V3 node subclasses inheriting the parent's cached schema values#16205
L4XB wants to merge 1 commit into
Comfy-Org:masterfrom
L4XB:fix/v3-subclass-schema-cache

Conversation

@L4XB

@L4XB L4XB commented Sep 9, 2026

Copy link
Copy Markdown

Fixes #16132
Fixes #16026 (same bug, reported for OUTPUT_IS_LIST)

Problem: The _RETURN_TYPES, _RETURN_NAMES, _OUTPUT_NODE, … sentinels on _ComfyNodeBaseInternal are plain class attributes. Once a parent V3 node has been schema'd (registration does this), every subclass inherits the populated values, so the is None guards in GET_SCHEMA() never fire for the subclass. A subclass that overrides define_schema() to change its outputs keeps the parent's RETURN_TYPES while SCHEMA (assigned unconditionally) is correct, and output validation in execution.py then indexes the stale tuple.

Change: _ComfyNodeBaseInternal.__init_subclass__ resets the cached values on every new subclass. shallow_clone_class / copy_class / lock_class build the clone namespace from the parent's __dict__ on purpose, so attributes the new class already carries in its own __dict__ are left untouched and clones keep the cached schema (no extra GET_SCHEMA per execution).

Tests: tests-unit/comfy_api_test/node_schema_cache_test.py covers the parent/child case from the issue and asserts that a class clone keeps the parent's cache. The first test fails on master and passes with this change.

pytest tests-unit/comfy_api_test tests-unit/nodes_test tests-unit/comfy_extras_test tests-unit/execution_test tests-unit/comfy_api_nodes_test tests-unit/prompt_server_test
797 passed, 2 skipped

Related: #16058 addresses #16026 by changing every is None guard to cls.__dict__.get(...). This PR takes the smaller route of resetting the caches once per subclass in __init_subclass__, so the guards and the clone behaviour stay as they are. Happy to close either one depending on which approach is preferred.

On the design question raised in #16026 ("should this class be prohibited from being inherited?"): with the reset in __init_subclass__ the cache is class-local by construction, so subclassing a V3 node keeps working (the reporter's own EmptyImage2(EmptyImage1) case relies on it) without any per-property inheritance checks.

The RETURN_TYPES, RETURN_NAMES, OUTPUT_NODE etc. sentinels are plain class
attributes, so once a parent V3 node was schema'd every subclass saw the
populated value and the `is None` guard in GET_SCHEMA never fired. A subclass
overriding define_schema to change its outputs kept the parent's RETURN_TYPES
and failed output validation at execution time.

Reset the cached values on every new subclass in __init_subclass__. Class
clones copy the parent's __dict__ on purpose, so attributes the new class
already carries are left alone.

Fixes Comfy-Org#16132
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged.
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 218c6958-e2b0-4983-9d7d-2c40fdb8eba7

📥 Commits

Reviewing files that changed from the base of the PR and between 6f3895e and 58a8a96.

📒 Files selected for processing (2)
  • comfy_api/latest/_io.py
  • tests-unit/comfy_api_test/node_schema_cache_test.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⚠️ CI failures not shown inline (2)

GitHub Actions: CLA Assistant / 0_cla-assistant.txt: Fix V3 node subclasses inheriting the parent's cached schema values

Conclusion: failure

View job details

##[group]Run contributor-assistant/github-action@ca4a40a7d1004f18d9960b404b97e5f30a505a08
 with:
   lock-pullrequest-aftermerge: false
   path-to-document: https://github.com/Comfy-Org/comfy-cla/blob/main/comfyui_icla.md
   remote-organization-name: comfy-org
   remote-repository-name: comfy-cla
   path-to-signatures: signatures/cla.json
   branch: main
   allowlist: action@github.com,actions-user,ampagent,claude,comfy-pr-bot,GitHub Action,github-actions,github-actions[bot],Glary Bot,Glary-Bot,*[bot]
   custom-notsigned-prcomment: 🎉 Thank you for your contribution, we really appreciate it! 🎉
Like many open source projects, we require contributors to sign our [Contributor License Agreement (CLA)](https://github.com/Comfy-Org/comfy-cla/blob/main/comfyui_icla.md). A CLA makes the ownership of contributions explicit, so contributors and the project share a clear understanding of how the code can be used. By signing, you:
- Confirm that you own your contribution.
- Keep the right to reuse your own code.
- Grant us a copyright license to include and share it within our projects.
CLAs are standard practice across major open source projects including those under the Apache Software Foundation and the Linux Foundation. Ours is based on the Apache Software Foundation's CLA. Most importantly, it would enable us to relicense the project under a more permissive license in the future, giving the project and its community greater flexibility.
✍ **To sign, please post a new comment on this PR with exactly the following text:** ✍
   custom-pr-sign-comment: I have read and agree to the Contributor License Agreement
   custom-allsigned-prcomment: ✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged.
   use-dco-flag: false
   suggest-recheck: true
 env:
   GITHUB_***REDACTED_SECRET_ASSIGNMENT***
   PERSONAL_ACCESS_***REDACTED_SECRET_ASSIGNMENT***
 ##[endgroup]
 CLA Assistant GitHub Action bot has started the process
 (node:2080) [DEP0040] DeprecationWar...

GitHub Actions: CLA Assistant / cla-assistant: Fix V3 node subclasses inheriting the parent's cached schema values

Conclusion: failure

View job details

##[group]Run contributor-assistant/github-action@ca4a40a7d1004f18d9960b404b97e5f30a505a08
 with:
   lock-pullrequest-aftermerge: false
   path-to-document: https://github.com/Comfy-Org/comfy-cla/blob/main/comfyui_icla.md
   remote-organization-name: comfy-org
   remote-repository-name: comfy-cla
   path-to-signatures: signatures/cla.json
   branch: main
   allowlist: action@github.com,actions-user,ampagent,claude,comfy-pr-bot,GitHub Action,github-actions,github-actions[bot],Glary Bot,Glary-Bot,*[bot]
   custom-notsigned-prcomment: 🎉 Thank you for your contribution, we really appreciate it! 🎉
Like many open source projects, we require contributors to sign our [Contributor License Agreement (CLA)](https://github.com/Comfy-Org/comfy-cla/blob/main/comfyui_icla.md). A CLA makes the ownership of contributions explicit, so contributors and the project share a clear understanding of how the code can be used. By signing, you:
- Confirm that you own your contribution.
- Keep the right to reuse your own code.
- Grant us a copyright license to include and share it within our projects.
CLAs are standard practice across major open source projects including those under the Apache Software Foundation and the Linux Foundation. Ours is based on the Apache Software Foundation's CLA. Most importantly, it would enable us to relicense the project under a more permissive license in the future, giving the project and its community greater flexibility.
✍ **To sign, please post a new comment on this PR with exactly the following text:** ✍
   custom-pr-sign-comment: I have read and agree to the Contributor License Agreement
   custom-allsigned-prcomment: ✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged.
   use-dco-flag: false
   suggest-recheck: true
 env:
   GITHUB_***REDACTED_SECRET_ASSIGNMENT***
   PERSONAL_ACCESS_***REDACTED_SECRET_ASSIGNMENT***
 ##[endgroup]
 CLA Assistant GitHub Action bot has started the process
 (node:2080) [DEP0040] DeprecationWar...
🧰 Additional context used
📓 Path-based instructions (2)
IMPORTANT: Only comment on issues directly introduced by this PR's code changes.

⚙️ CodeRabbit configuration file

Files:

  • tests-unit/comfy_api_test/node_schema_cache_test.py
  • comfy_api/latest/_io.py
Documentation and README edits should be concise, factual, and tied to the changed behavior.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • tests-unit/comfy_api_test/node_schema_cache_test.py
  • comfy_api/latest/_io.py
🔇 Additional comments (2)
comfy_api/latest/_io.py (1)

1979-1994: LGTM!

tests-unit/comfy_api_test/node_schema_cache_test.py (1)

1-48: LGTM!


📝 Walkthrough

Walkthrough

_ComfyNodeBaseInternal now resets absent schema, metadata, input/output, caching, and compatibility attributes when a subclass is created. This prevents subclasses from reusing populated parent cache values. New tests verify that subclasses compute independent schema values and that PREPARE_CLASS_CLONE preserves shared cache references.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 58a8a

V3 subclasses now compute schema metadata from their own definitions instead of inheriting populated parent caches, while cloned node classes retain their existing caches. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #16132 by resetting inherited cached schema attributes for each subclass. The tests cover the parent-child schema case and confirm that class clones retain cached values.
Out of Scope Changes check ✅ Passed The implementation and tests are directly related to fixing cached schema inheritance and preserving clone behavior. No unrelated changes are identified.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing V3 node subclasses from inheriting cached schema values.
Description check ✅ Passed The description directly explains the bug, the cache-reset fix, clone behavior, affected attributes, linked issues, and test coverage.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@L4XB

L4XB commented Sep 9, 2026

Copy link
Copy Markdown
Author

I have read and agree to the Contributor License Agreement

comfy-legal added a commit to Comfy-Org/comfy-cla that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants