Skip to content

🐛 Propagate Pydantic's model config #12504

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

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

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.

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.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy