-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
UUID type Field
doesn't support strict
specification
#7838
Comments
Actually... this is a somewhat different problem than I thought, and got a slightly more simple example. Turns out the class-level config doesn't matter, and even this is sufficient: >>> class UnstrictExample(pydantic.BaseModel):
... id: uuid.UUID = pydantic.Field(strict=False)
... val: int
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 178, in __new__
complete_model_class(
...
File "/usr/local/lib/python3.11/site-packages/pydantic/_internal/_known_annotated_metadata.py", line 239, in apply_known_metadata
raise RuntimeError(f'Unable to apply constraint {constraint} to schema {schema_type}')
RuntimeError: Unable to apply constraint strict to schema uuid |
Thanks for reporting this. This indeed looks like a bug 🐛. I'll work to get a fix out for this soon 👍. |
Appreciated; thanks a bundle! |
Field
doesn't support strict
specification
Just merged a fix. This should be fixed in the next release 😄. |
A couple hours to confirm and less than two days for a fix... absolutely brilliant. Thank you very much, I look forward it making a release! |
Initial Checks
Description
This seems to be closely related to #7759 which is marked fixed, but if I installed the current
main
correctly it doesn't seem to be fixed there.I would like to make a class that is, in general, strict, but where that strictness is relaxed for
UUID
fields so I can get conversions from strings rather than have to pre-convert those:With Pydantic 2.1, this works:
However, upgrade to 2.2, and it does not:
and this remains true if I
pip install 'git+https://github.com/pydantic/pydantic@main#egg=pydantic'
(though it may be installingpydantic-core
from somewhere else...? I'm not sure I'm checking current trunk correctly; sorry if this is fixed after all.)Example Code
Python, Pydantic & OS Version
Running from
python:3.11-slim-bookworm
Docker container, but I get similar with 3.8 in a local venv. Here's the version information for 2.2:The text was updated successfully, but these errors were encountered: