Skip to content
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

UUID4 validation from string not strict enough #1164

Closed
1 task done
hassec opened this issue Jan 15, 2024 · 1 comment · Fixed by #1172
Closed
1 task done

UUID4 validation from string not strict enough #1164

hassec opened this issue Jan 15, 2024 · 1 comment · Fixed by #1172

Comments

@hassec
Copy link

hassec commented Jan 15, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

The string representation of "00000000-0000-4000-0000-000000000000", is not a valid UUID because the first digit of the fourth group would have to be one of [8,9,a,b].

See attached example, I think that both instantiations of A(..) should throw a validation error.

image

Example Code

from pydantic import BaseModel, UUID4
import uuid

class A(BaseModel):
    x: UUID4


not_u4_str = "00000000-0000-4000-0000-000000000000"
not_u4 = uuid.UUID(not_u4_str)
print(not_u4.version)
A(x=not_u4_str)
A(x=UUID('00000000-0000-4000-0000-000000000000'))

Python, Pydantic & OS Version

pydantic version: 2.5.3
        pydantic-core version: 2.14.6
          pydantic-core build: profile=release pgo=true
                 install path: /Users/chasse/software/pyenv/versions/3.10.13...
               python version: 3.10.13 (main, Sep 10 2023, 20:18:32) [Clang 14.0.3 (clang-1403.0.22.14.1)]
                     platform: macOS-14.2.1-arm64-arm-64bit
             related packages: typing_extensions-4.9.0
@sydney-runkle
Copy link
Member

@hassec,

Thanks for reporting this. This does seem like a bug, but one for pydantic-core. Moving it there now 👍

@sydney-runkle sydney-runkle transferred this issue from pydantic/pydantic Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants