Skip to content

Fix bug introduced in #14482 which breaks openapi generation in special cases#14805

Open
ilovemesomeramen wants to merge 2 commits intofastapi:masterfrom
ilovemesomeramen:master
Open

Fix bug introduced in #14482 which breaks openapi generation in special cases#14805
ilovemesomeramen wants to merge 2 commits intofastapi:masterfrom
ilovemesomeramen:master

Conversation

@ilovemesomeramen
Copy link

#14482 added the model_config to the ModelField to support arbitrary types, however the if statement did not check for all the correct types.

This PR brings the check inline with the internal pydantic TypeAdapter check which would throw an error in some cases, e.g. Union fields with single Values.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 2, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing ilovemesomeramen:master (7e1da42) with master (bc9ad6b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (82959de) during the generation of this report, so bc9ad6b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@YuriiMotov
Copy link
Member

@ilovemesomeramen, thank you for your interest and efforts!
Can you come up with a more realistic code example? Ideally something that we can not do in a simpler way

@ilovemesomeramen
Copy link
Author

@YuriiMotov What do you mean exactly?

The provided example is exactly the issue which this PR solved, this example worked in 0.124.0 but does not in 0.124.1

A little bit of context why this is needed:
I often design my APIs in such a way that it easy to extend the models in the future.
So if i know a specific model will be discriminated in the future i want the OpenAPI spec to reflect that immediately.

the provided test case is based on this test: tests/test_arbitrary_types.py

The Problem is the Union with a single value in it this worked before and no longer works since the type is not properly extracted.

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.

2 participants