Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RB387
Copy link

@RB387 RB387 commented Oct 21, 2024

Related discussion:
#12503

@RB387 RB387 changed the title fix: Propagate Pydantic's model config 🐛 fix: Propagate Pydantic's model config Oct 22, 2024
@alejsdev alejsdev changed the title 🐛 fix: Propagate Pydantic's model config 🐛 Propagate Pydantic's model config Oct 22, 2024
@alejsdev alejsdev added the bug Something isn't working label Oct 22, 2024
@RB387
Copy link
Author

RB387 commented Oct 23, 2024

@alejsdev @tiangolo hey hey folks 👋
Is there any chance that this PR can be merged any time soon?
It's blocking us at Wolt unfortunately from upgrading FastAPI to the latest version 😞

@tiangolo
Copy link
Member

I haven't checked this thoroughly but I suspect it should be fixed in Pydantic in TypeAdapter, and that should be what respects the internal configs. E.g. TypeAdapter(list[Model]) should also work, but I would suspect it's not working.

I haven't played with it locally yet, running the code, etc. I might be wrong.

@RB387
Copy link
Author

RB387 commented Oct 23, 2024

Yep, you are correct.

It seems that the problem is more complex than I initially thought. TypeAdapter indeed does use the model config, but the issue is that the config is not applied to the root model. This occurs because the root model is not wrapped by the TypeAdapter, and all fields are extracted separately from it. Therefore, this is why Pydantic is unaware of any config related to the root model.

So yeah, my PR does not work. I added to this PR test case that should pass

@shrey1605
Copy link

Is this issue still open? Looking to contribute

@RB387
Copy link
Author

RB387 commented Oct 24, 2024

@shrey1605 yep, issue is still open

@rmawatson
Copy link
Contributor

Some more info on this here. Worth noting it seems you can work around this by adding a second dummy parameter to

@app.post("/")
async def read_root(a: Model, b :Model = Model()) -> bool:
    return True

The issue lies with this , from this commit.

@rmawatson
Copy link
Contributor

rmawatson commented Jun 25, 2025

this PR should fix the problem discussed here.

@YuriiMotov
Copy link
Member

#13694 contains the test case from this PR and approaches to solve the issue.
Let's close this PR in favor of #13694.

@RB387, thank you for your efforts!

@YuriiMotov YuriiMotov closed this Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants