Skip to content

Weird Uuid::default() implementation #530

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

Open
tyilo opened this issue May 2, 2025 · 3 comments
Open

Weird Uuid::default() implementation #530

tyilo opened this issue May 2, 2025 · 3 comments
Assignees
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@tyilo
Copy link
Contributor

tyilo commented May 2, 2025

The current Default implementation for Uuid returns Uuid::new() which returns a random UUID v4.

This is different from uuid::Uuid::default() which returns the nil UUID, which seems like a more reasonable default. I would normally expect that T::default() == T::default().

I think Uuid::default() should be changed to match uuid::Uuid and return a nil UUID.

@abr-egn
Copy link
Contributor

abr-egn commented May 19, 2025

Agreed that it's weird, and that the nil UUID would be a better choice for return value. Unfortunately, simply changing it seems like it'd be at high risk of silently breaking existing code in unpleasant ways (e.g. data loss) given the way default can be implicitly used in a lot of contexts to provide fresh values.

I've created RUST-2218 to track potentially including this in the next major version.

@abr-egn abr-egn added tracked-in-jira Ticket filed in Mongo's Jira system and removed triage labels May 19, 2025
@abr-egn
Copy link
Contributor

abr-egn commented May 27, 2025

We discussed this in the team and we're not sure there's enough value here compared to the risk to make this change, even at a major version boundary; if we were to do something like this we'd want to remove the Default impl entirely in 4.0 to make it a compile-breaking change and then re-introduce it in 4.1 with the new behavior.

Do you have a specific use case in mind for this?

@tyilo
Copy link
Contributor Author

tyilo commented May 27, 2025

Do you have a specific use case in mind for this?

No, I was just reviewing some code using Uuid::default() and got confused why it worked, as I knew that uuid::Uuid::default() returns the nil UUID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

No branches or pull requests

2 participants