Skip to content

fix: resolve RecursionError for self-referencing schemas#306

Open
mojixcoder wants to merge 1 commit into
tadata-org:mainfrom
mojixcoder:fix/recursion-error-self-referencing-schemas
Open

fix: resolve RecursionError for self-referencing schemas#306
mojixcoder wants to merge 1 commit into
tadata-org:mainfrom
mojixcoder:fix/recursion-error-self-referencing-schemas

Conversation

@mojixcoder
Copy link
Copy Markdown

@mojixcoder mojixcoder commented May 23, 2026

Describe your changes

resolve_schema_references() would raise a RecursionError when the OpenAPI schema contained a self-referencing (recursive) Pydantic model — e.g. a CompoundFilter that contains a list of CompoundFilter | ComparisonFilter.

Root cause: The function unconditionally expanded every $ref it encountered, including back-references to a schema already being expanded, leading to infinite recursion.

Fix: Added a _visited parameter (a frozenset of $ref paths currently on the expansion stack). When a $ref is encountered that is already in _visited, the function returns the $ref in place rather than expanding it, breaking the cycle.

Test: Added test_self_referencing_schema_does_not_raise_recursion_error with a minimal recursive model (CompoundFilter → List[ComparisonFilter | CompoundFilter]) to guard against regressions.

Issue ticket number and link (if applicable)

Clsoes #287

Screenshots of the feature / bugfix

Checklist before requesting a review

  • Added relevant tests
  • Run ruff & mypy
  • All tests pass

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.

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