Skip to content

fix: prevent infinite recursion in update_forward_refs for self-referencing DTOs#10

Merged
allmonday merged 3 commits into
masterfrom
fix/voyager-self-ref-recursion
May 15, 2026
Merged

fix: prevent infinite recursion in update_forward_refs for self-referencing DTOs#10
allmonday merged 3 commits into
masterfrom
fix/voyager-self-ref-recursion

Conversation

@allmonday
Copy link
Copy Markdown
Owner

Bug

update_forward_refs in type_helper.py recurses infinitely when a DefineSubset DTO references itself (e.g. replies: list["CommentDTO"]).

Root Cause

No visited-set — self-referencing types cause unbounded recursion through field annotations.

Fix

Added _visited: set | None = None parameter to track already-processed types. On re-encounter, the type is skipped since model_rebuild() already resolved its forward refs on the first visit.

Changed Files

  • src/sqlmodel_nexus/voyager/type_helper.py — add visited-set guard (+5 lines)
  • tests/test_voyager_selfref.py — flip test from pytest.raises(RecursionError) to assert normal completion

allmonday and others added 3 commits May 15, 2026 17:03
…encing DTOs

Add _visited set to track already-processed types, breaking recursion
cycles when a DefineSubset DTO references itself (e.g. replies: list["CommentDTO"]).
- Add missing UseCaseService import in voyager_context.py
- Replace mutable default `tags: list[str] = []` with `None` in test
- Apply ruff auto-fixes: unused imports, blank lines, getattr simplification

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ault fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@allmonday allmonday merged commit 25867ee into master May 15, 2026
3 checks passed
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