Skip to content
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

Address root model feedback #5820

Merged
merged 1 commit into from
May 24, 2023
Merged

Address root model feedback #5820

merged 1 commit into from
May 24, 2023

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented May 22, 2023

Closes #5818

The main change here is that I've reworked the signature of model_construct for RootModel subclasses in such a way that model_construct assumes the first positional argument is actually the root value, letting you not specify the keyword argument if you prefer not to. (The fields_set can still be passed as the now-second positional argument.)

@commonism I think the other issues you raised were related to the fact that you still need to perform validation to convert a str to a RootModel[str], and that doesn't happen automatically when you call model_construct (since skipping validation is the whole point of model_construct). But I've added tests in this PR that document the current behavior and show it works if you do do the construction all the way down.

@commonism I won't merge until we've discussed whether you feel this addresses your issues.

Selected Reviewer: @hramezani

@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: a9af967
Status: ✅  Deploy successful!
Preview URL: https://7368e838.pydantic-docs2.pages.dev
Branch Preview URL: https://address-root-model-feedback.pydantic-docs2.pages.dev

View logs

@dmontagu
Copy link
Contributor Author

please review

@dmontagu
Copy link
Contributor Author

@hramezani@commonism gave approval to merge these changes in #5818 so feel free to merge after reviewing.

@hramezani hramezani merged commit e190c25 into main May 24, 2023
43 checks passed
@hramezani hramezani deleted the address-root-model-feedback branch May 24, 2023 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RootModel does not work with Base64Str
2 participants