Open guyzmo opened 1 month ago
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. I believe this ticket should still stay open as at least we should clarify this usage in the Indexes docs, to avoid any future confusion.
ok, I did upgrade to latest, and that did solve the issue, so yes:
Annotated[str, Indexed(str, unique=True)]
was broken in older versions of beanieAnnotated[str, Indexed(unique=True)]
was not implemented in older versions of beaniethank you š
Hi @guyzmo, glad to see the issue resolved for you and thank you for opening this ticket.
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.