-
Notifications
You must be signed in to change notification settings - Fork 791
fix: allow for self-referencing pydantic schema #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
validated locally on my machine. This solves the recursion issue. Please review and merge this fix in! Important |
I have been using it also. It seems to work. |
Hello - another passive observer here who would love to see this change included in a future release 🤗 |
First time using this app, encountered this problem, request merge this PR, please... |
@shahar4499 request merge |
def resolve_schema_references( | ||
schema_part: Dict[str, Any], | ||
reference_schema: Dict[str, Any], | ||
seen: Optional[Set[str]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add this to the docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks
As a temporary workaround you can copy this function in your code to patch the current implementation: fastapi_mcp.openapi.utils.resolve_schema_references = resolve_schema_references |
0d3adf2
to
d416df8
Compare
Edit: I rewrote my comment because I made the original in a hurry in the end of my day and realized it was basically unreadable. Hi, thank you very much for your solution. I used it and came across a small mistake, or at least unexpected behavior, it causes for one of my models. This happens in cases where you have a model that has two or more properties of the same type, like Game has here:
I would expect playerA and platerB to be represented by the same structure and only occurrences of Player in deeper nested positions to be replaced by some pointer, stopping the endless chain of recursion. But since there is one global "seen" set passed around here everything after the first encounter is replaced by a pointer (PlayerB in this case), not only those in nested positions. This change, fixes the problem for me: |
Describe your changes
This PR introduces a new field
related_products
in theProducts
fixture which replicates the failure case mentioned in #155 and makes existing tests fail with aRecursionError
as expected. Then we add a newseen
set to the functionresolve_schema_references
which resolves the error and makes the tests pass again.Issue ticket number and link (if applicable)
Fixes #155
Checklist before requesting a review