-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
👽️ Support Pydantic version 2.10 #1215
base: main
Are you sure you want to change the base?
Conversation
Without this fix, any SQLModel-based model with `table=True` and a `Field` that sets `default_factory=...` will brake with the following error message: `ValueError: 'validated_data' must be provided if 'call_default_factory' is True.`
Without this fix, any SQLModels with a `Field` that uses `default_factory=...` will brake with the following error message: `ValueError: 'validated_data' must be provided if 'call_default_factory' is True`. Made the fix backwards compatible.
Note that we added a quick fix in 2.10.1 to not raise the error. But indeed, SQLModel should support default factories taking a The (I'll also note that having SQModel relying so much on Pydantic is a bit scary, but well..) |
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.
Hi @mtr, thanks for the contribution!
It looks like this PR was made from https://github.com/encount/sqlmodel/tree/main and I can't push to that branch to make this PR up-to-date with the latest changes in the CI. Would you be able to change those permissions? Typically, maintainers of a repo should be allowed push access on a PR for the reviewing process to go more smoothly. Thanks!
Just FYI - you should see a box like this on your right hand side of the PR screen:
Hi, @svlandeg. Where can I find that setting that you showed an image of? I didn't find it, but ran a quick (automatic) sync with upstream repo. Hope that helps in the meantime. |
@mtr: it should be on the right-hand side of the main PR screen, below the sections "Milestone", "Development" and "participants" (you can ctrl-F those). If you don't see such a box, that may be because this PR was created from the fork over at https://github.com/encount/sqlmodel/. I'm not sure how to fix things if that's the case - usually users create PRs from their own forks 🤔 |
PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA = ( | ||
"validated_data" in inspect.signature(FieldInfo.get_default).parameters | ||
) |
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.
Can't a version check be done instead? I think it would clearer with a comment:
PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA = ( | |
"validated_data" in inspect.signature(FieldInfo.get_default).parameters | |
) | |
# Pydantic 2.10 added support for default factories taking validated data: | |
PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA = IS_PYDANTIC_210 |
Without this fix, any SQLModel-based model with
table=True
and aField
that setsdefault_factory=...
will brake with the following error message:ValueError: 'validated_data' must be provided if 'call_default_factory' is True.
To reproduce, before this fix is applied:
Install all project dependencies, then upgrade Pydantic:
Run the test suite:
… which will give the following output: