-
-
Notifications
You must be signed in to change notification settings - Fork 752
π₯ Rename regex
to pattern
to provide compatibility with Pydantic V2
#1231
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
Conversation
8559f01
to
6afa967
Compare
regex
to param
to provide compatibility with Pydantic V2 (θΏ½θ¨γγγΎγ§)
Thanks for the PR! We're going through the backlog of PRs right now, and will get back to you once we've had the time to review this and consider the (breaking) change π
@svlandeg Nice to hear you are taking action on this matter. There is remark, the parameter the was renamed between Pydantic v1 and v2 is regex
-> pattern
, not as listed in the PR.
The suggestion I made in the PR was to keep both versions compatible when upgrading, but there is an alternative, which is not managing the change between them and just provide the proper type hints.
If you want me to update the PR just let me know, IDK which approach is more adequate for the project.
@stickM4N, could you please clarify why this should be treated as breaking change?
Apart from that, should we add a test for new parameter?
regex
to param
to provide compatibility with Pydantic V2 (ει€γγγΎγ§)regex
to pattern
to provide compatibility with Pydantic V2 (θΏ½θ¨γγγΎγ§)
Hi @YuriiMotov, nice to hear from you again.
Sorry for not have given a better description for the problem, but here it is:
from sqlmodel import SQLModel, Field class MyClass(SQLModel): id: str = Field(unique=True, pattern=r"^\d{5}$")
This code raises TypeError: Field() got an unexpected keyword argument 'pattern'
which is the intended keyword for pydantic.v2.FieldInfo
, differet from regex
for pydantic.v1.FieldInfo
The aim of this PR is to make them compatible and have the same logic for both version sqlmodel
-wise
I have other proposition that is more comfortable to work with in my opinion, but its more of a change... and its to convert schema_extra
param to **schema_extra
, so the input from sqlmodel.Field
is more flexible, should not have impacts in other places and it add flexibility to implementations and simpler way to migrate from pydantic.Field
to sqlmodel.Field
Since we still support regex
parameter and just add alias (pattern
) and make it working with Pydantic V2, I wouldn't call these changes braking.
So, I would remove the mention of breaking.
Also, I think we should mark regex
as deprecated and prioritize pattern
over regexp
regardless the version of Pydantic.
Still we need to add some test:
- pass
regex
and validate valid\invalid value - pass
pattern
and validate valid\invalid value - pass both
regex
andpattern
and see thatpattern
is used - don't pass
pattern
directly, but passschema_extra={"pattern": r"..."}
(workaround that is currently being used to make it working with Pydantic V2) - it should still work
Noted @YuriiMotov, I will do that.
Here there is the reference to the removed parameter and error raise associated to it. Here is its implementation.
I would like to propose the following change:
def Field(default, *, ..., **schema_extra)
rather than
def Field(default, *, ..., schema_extra)
f78503b
to
3f99f49
Compare
a5e8961
to
0b9f96f
Compare
Uh oh!
There was an error while loading. Please reload this page.
I faced this issue with Pydantic V2 and there is a simple workaround to it by passing the
pattern
Field parameter as schema extra:Ex:
This should be labeled as breaking
I don't know if this issue was already fixed in another branch, I saw there was a temporary PR already made but closed.