Skip to content

Conversation

@KimigaiiWuyi
Copy link

@KimigaiiWuyi KimigaiiWuyi commented Jul 26, 2024

According to what this link mentions,

PydanticV1's Field class supported passing arbitrary keyword arguments to the JSON schema. In SQLModel counterpart, it was supported by passing schema_extra (see this).

PydanticV2 still supports passing extra things to the JSON schema but in a slightly different way. One has to pass a dictionary in the json_schema_extra argument (see this).

Field no longer supports arbitrary keyword arguments to be added to the JSON schema. Instead, any extra data you want to add to the JSON schema should be passed as a dictionary to the json_schema_extra keyword argument.

So I modified the Field's parameters to be compatible and consistent with the Pydantic v2 parameters, and for backward compatibility, I didn't remove the schema_extra field, which is logically compatible with both the schema_extra and json_schema_extra passes, and schema_extra should be deprecated at some point in the future. field at some point in the future, but for now schema_extra should be retained.

This Pull Reqeust is easy and simple, and easy to verify.

@Kaplas85
Copy link

Any news about this PR?

@ndeybach
Copy link

ndeybach commented Dec 26, 2024

Any possibility of a merge @tiangolo ? I would also be interested in this support being added / long term.

@paulomtts
Copy link

Please merge this.

@svlandeg svlandeg changed the title 🎨 Field() supports json_schema_extra for Pydantic v2 Field() supports json_schema_extra for Pydantic v2 Feb 24, 2025
@svlandeg svlandeg added the feature New feature or request label Feb 24, 2025
@arnoldasjan
Copy link

can you merge this?

YuriiMotov

This comment was marked as resolved.

@KimigaiiWuyi

This comment was marked as resolved.

@github-actions

This comment was marked as outdated.

@github-actions github-actions bot closed this Sep 22, 2025
@YuriiMotov

This comment was marked as resolved.

@TATOAO

This comment was marked as resolved.

@KimigaiiWuyi
Copy link
Author

PR was closed due to inactivity for 30 days..

@KimigaiiWuyi, would you like to continue working on this? I can re-open it

yes, I can handle it. Help me reopen it. Should I add test cases for it?

@svlandeg svlandeg reopened this Sep 26, 2025
@github-actions github-actions bot removed the waiting label Sep 26, 2025
@YuriiMotov

This comment was marked as resolved.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2025

📝 Docs preview

Last commit 249ad47 at: https://5ef99040.sqlmodel.pages.dev

@KimigaiiWuyi

This comment was marked as resolved.

@github-actions github-actions bot removed the waiting label Oct 3, 2025
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Oct 8, 2025
@github-actions

This comment was marked as resolved.

YuriiMotov

This comment was marked as outdated.

@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Oct 8, 2025
KimigaiiWuyi and others added 2 commits October 8, 2025 20:34
Co-authored-by: Motov Yurii <[email protected]>
@YuriiMotov YuriiMotov changed the title Field() supports json_schema_extra for Pydantic v2 ✨ Add json_schema_extra and pydantic_kwargs params to Field() and deprecate schema_extra Oct 8, 2025
@YuriiMotov

This comment was marked as resolved.

@YuriiMotov

This comment was marked as resolved.

@KimigaiiWuyi

This comment was marked as resolved.

@YuriiMotov
Copy link
Member

@KimigaiiWuyi, I suggested my way of fixing this, please review:

  • Removed pydantic_kwargs parameter, updated texts that mentioned it
  • Renamed pydantic_kwargs local var into field_info_kwargs as it's used in parallel PR we are working on
  • Only show deprecation warning when deprecated schema_extra parameter is used - we can't raise RuntimeError as we don't support all Pydantic-related parameters yet
  • Simplified logic of handling schema_extra with Pydantic V2 installed
  • Conditionally use model_json_schema or schema in tests depending on Pydantic version
  • Only test workaround with json_schema_extra being passed via schema_extra for Pydantic V2 - it doesn't make sense with Pydantic V1

@YuriiMotov YuriiMotov changed the title ✨ Add json_schema_extra and pydantic_kwargs params to Field() and deprecate schema_extra ✨ Add json_schema_extra and deprecate schema_extra Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants