-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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 constructor accept invalid strings (extra dash) #80938
Comments
UUID constructor accept string with too many dashes or keyword like urn: / uuid: For eg, this code do not raise
For the context, we use a validator based on We workaround this in our validator, but UUID constructor should not accept string like the one in exemple |
The documentation does describe a fairly flexible parser. Perhaps it's a little too flexible on stuff like URN prefixes, but I don't think we could start enforcing a stricter class of hyphen separations without potentially breaking existing code. Is there are reason your validator doesn't use uuid.UUID to normalize the value? That is, whatever the customer provides, why not use the result of stringifying the resulting UUID, rather than just convert to UUID to validate, then throwing it away? As long as the result is compatible with your sql connector, and logically equivalent to what the customer provided, that seems a valid solution. |
Yes, this is exactly what we do now However this behaviour is a bit surprising, we were thinking that uuid.UUID could be used as a validator I understand the risk of breaking existing code with a fix that enforce a strict form. Maybe a line should be added in the documentation to prevent people using this as a validator without more check? But ok, you can close the bug if you prefer ... I think there no perfect solution :-) |
I don't expect uuid.UUID could be used as a validator myself, but I agreed we can warn users in the documentation if lots of them confuse about it. |
I too find this surprising, especially given how thoroughly UUID validates inputs of types other than "hex". The documentation simply states that for hex input, hypens, curly braces and a URN prefix are optional. In practice, though, it is much more lenient than that, as described here. Since the UUID has no expert listed, we'll have to decide whether to make the input validation stricter and break backwards-compatibility, or simply make the docs clearer. Clarifying the docs certainly seems simpler, safer and more user-friendly. It also seems reasonable, given that this issue apparently hasn't affected many users. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: