Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

👽️ Support Pydantic version 2.10#1215

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
mtr wants to merge3 commits intofastapi:main
base:main
Choose a base branch
Loading
fromencount:main
Draft

Conversation

mtr
Copy link

@mtrmtr commentedNov 15, 2024

Without this fix, any SQLModel-based model withtable=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:

    pip install -r requirements.txtpip install pydantic==2.10.0b2
  • Run the test suite:

    python -m pytest tests

… which will give the following output:

[…]=================================================================== short test summary info ====================================================================FAILED tests/test_annotated_uuid.py::test_annotated_optional_types - ValueError: 'validated_data' must be provided if 'call_default_factory' is True.FAILED tests/test_advanced/test_uuid/test_tutorial001.py::test_tutorial - ValueError: 'validated_data' must be provided if 'call_default_factory' is True.FAILED tests/test_advanced/test_uuid/test_tutorial001_py310.py::test_tutorial - ValueError: 'validated_data' must be provided if 'call_default_factory' is True.FAILED tests/test_advanced/test_uuid/test_tutorial002.py::test_tutorial - ValueError: 'validated_data' must be provided if 'call_default_factory' is True.FAILED tests/test_advanced/test_uuid/test_tutorial002_py310.py::test_tutorial - ValueError: 'validated_data' must be provided if 'call_default_factory' is True.===================================================== 5 failed, 250 passed, 3 skipped, 7 warnings in 9.37s =====================================================

TheTechromancer, liquidsec, Nazareka, ahasha, and svlandeg reacted with heart emoji
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.
@Viicos
Copy link

Note that we added a quick fix in 2.10.1 to not raise the error. But indeed, SQLModel should support default factories taking avalidated_data argument.

TheBaseModel.model_construct implementation was updated to take into account this feature, so it might be good looking at how we did it. Might be good looking at the other fixes that were introduced since then (e.g.pydantic/pydantic#9223).

(I'll also note that having SQModel relying so much on Pydantic is a bit scary, but well..)

svlandeg reacted with thumbs up emoji

@svlandegsvlandeg changed the titleSupport upcoming changes in Pydantic version 2.10👽️ Support Pydantic version 2.10Feb 20, 2025
Copy link
Member

@svlandegsvlandeg left a comment
edited
Loading

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 fromhttps://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:

image

@svlandegsvlandeg added the bugSomething isn't working labelFeb 24, 2025
@svlandegsvlandeg marked this pull request as draftFebruary 24, 2025 10:40
@mtr
Copy link
Author

mtr commentedFeb 24, 2025

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.

@svlandeg
Copy link
Member

svlandeg commentedFeb 28, 2025
edited
Loading

@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 athttps://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 🤔

Comment on lines +85 to +87
PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA = (
"validated_data" in inspect.signature(FieldInfo.get_default).parameters
)
Copy link

@ViicosViicosFeb 28, 2025
edited
Loading

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:

Suggested change
PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA= (
"validated_data"ininspect.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

@mtr
Copy link
Author

mtr commentedMar 5, 2025 via email

Sure, a version test could be done instead. I wanted to test for theexistence `validated_data` parameter because that was the cause of theissue.
On Fri, Feb 28, 2025 at 11:24 AM Victorien ***@***.***> wrote: ***@***.**** commented on this pull request. ------------------------------ In sqlmodel/_compat.py <#1215 (comment)>: > + PYDANCTIC_FIELD_GET_DEFAULT_REQUIRES_VALIDATED_DATA = ( + "validated_data" in inspect.signature(FieldInfo.get_default).parameters + ) Can't a version check be done instead? I think it would clearer with a comment: ⬇️ Suggested change - 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 — Reply to this email directly, view it on GitHub <#1215 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABNHZCQCBF4IVH4HRS42KD2SA2NPAVCNFSM6AAAAABR253SQGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDMNJQGM2TCNBWHA> . You are receiving this because you were mentioned.Message ID: ***@***.***>
-- Kind regards,Martin Thorsen Ranang, *Ph.D*CEO | Encount ASphone:linkedin:location:+47 95853086https://www.linkedin.com/in/ranang/Fredrikstad, Norway

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@svlandegsvlandegsvlandeg left review comments

@ViicosViicosViicos left review comments

Assignees
No one assigned
Labels
bugSomething isn't working
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mtr@Viicos@svlandeg

[8]ページ先頭

©2009-2025 Movatter.jp