-
Notifications
You must be signed in to change notification settings - Fork 217
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
[BUG] When doing Annotated[str, Indexed(str, unique=True)] the uniqueness is not enforced #1036
Comments
It looks like this issue has been fixed in the PR #762. Found it thanks to the community on discord 🫶 Though, I'm not up to date, so I'm upgrading and come back here to tell whether it fixed my issue or not. I hope it does 🤞 |
When used with Annotated, you shouldn't provide the type to the Indexed function. Try this instead: class User
user_id: Annotated[str, Indexed(unique=True)] |
Hi @MrEarle, thank you for the explanation. I just looked at the code as was having a hard time to understand why we can't also provide the type in this case also, but I see now that this is by design. |
ok, I did upgrade to latest, and that did solve the issue, so yes:
thank you 🙏 |
Hi @guyzmo, However, I would like to leave this ticket as open until we make a note about this in our documentation. |
Describe the bug
As described in this issue
And discussed in this issue
And implemented in this PR
And according to beanie's documentation as well as pymongo's documentation
we can declare indexes with the following syntax:
To Reproduce
But if we want to declare an index with the uniqueness property, it is not enforced:
Expected behavior
There should be only one user with a given user_id, not two:
Additional context
I'm still running an older version of beanie (v1.11.6), but it looks like this issue is still actual. Cf discord.
The text was updated successfully, but these errors were encountered: