You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The regex used to validate a string in pydantic.Field will allow a string that does not match the given pattern to pass without raising a validation error.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
This simple regex checks for any number of lowercase letters ("a - z") and spaces.
In the example below, the test="this Should Fail" should raise a validation error. It does not. I think this is because it is using re.match instead if re.fullmatch.
importreimportpydanticclassTest(pydantic.BaseModel):
test: str=pydantic.Field(regex="[a-z ]+", description="Allow lower case letters and spaces")
try:
Test(test="this should pass")
exceptpydantic.ValidationError:
print("This should have passed!")
try:
Test(test="this Should Fail")
exceptpydantic.ValidationError:
print("This should have failed!")
assertbool(re.fullmatch("[a-z ]+", "this should pass"))
assertnotbool(re.fullmatch("[a-z ]+", "this Should Fail"))
Happy to submit a PR! (Looks like a nice easy one)
The text was updated successfully, but these errors were encountered:
Bug
The
regex
used to validate a string inpydantic.Field
will allow a string that does not match the given pattern to pass without raising a validation error.Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:This simple regex checks for any number of lowercase letters ("a - z") and spaces.
In the example below, the
test="this Should Fail"
should raise a validation error. It does not. I think this is because it is usingre.match
instead ifre.fullmatch
.Happy to submit a PR! (Looks like a nice easy one)
The text was updated successfully, but these errors were encountered: