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 Cast Error #2147
Comments
Does Postgres accept those as valid UUIDs? |
Accepts them just fine. I think the |
We relaxed the validations in the 2.1 branch and released 2.1.6 with the fix. The validations will be kept on the 2.2 branch and |
@michalmuskala As far as I can tell, RFC 4122 only uses the version and variant for the creation of Time-Based, Name-Based, and Random Number UUIDs. In fact, Section 3 states:
The example implementation at the bottom of the RFC does not validate UUIDs. ITU-T Rec. X.667 also states in Section 10:
Other standards, like ISO/IEC 9834-8, also focus primarily on the generation of UUIDs. Neither PostgreSQL, MySQL, MongoDB, Oracle, nor SQL Server validate UUIDs in any way beyond checking that they represent 128-bits, 16-bytes, or are composed of 32-bytes of hexadecimal characters (36 if you include the hyphens).
The current (Ecto 2.2) UUID validation also rejects the Nil UUID as specified in Section 4.1.7 of RFC 4122: iex> Ecto.UUID.cast(<<0::128>>)
:error I use ULID for UUIDs that are lexicographically sortable, which is not currently compatible with Ecto 2.2. So, all of that said: I do not think there is any basis that Ecto should be validating UUIDs in its current form (ie. validating version and variant). |
Also, I'd be happy to submit a pull request, but wanted to see if anyone had a differing opinion first 😀 |
Thank you @potatosalad! I have reverted those changes and pushed to master! |
Huzzah! My weird ids work again! Thanks, @josevalim. |
I guess I can't say anything other than: "I'm convinced" 😃 |
Took me a while to track down the change in #2056, but
UUID.cast/1
fails rather non-obviously if UUIDs don't conform exactly to the UUIDv4 spec. I have some legacy data where integer primary keys had been migrated to UUIDs by padding with zeros (e.g."00000000-0000-0000-0000-000000000034"
)Resulting error:
Unsure whether the validation should be reversed or just better noted in the docs.
Environment
The text was updated successfully, but these errors were encountered: