11"""FastAPI Users database adapter for Beanie."""
2- from typing import Any , Dict , Generic , Optional , Type , TypeVar
2+
3+ from typing import Any , Generic , Optional , TypeVar
34
45import bson .errors
56from beanie import Document , PydanticObjectId
@@ -23,9 +24,12 @@ class BeanieBaseUser(BaseModel):
2324 class Settings :
2425 email_collation = Collation ("en" , strength = 2 )
2526 indexes = [
26- IndexModel ("email" , unique = True ),
27+ IndexModel ("email" ),
2728 IndexModel (
28- "email" , name = "case_insensitive_email_index" , collation = email_collation
29+ "email" ,
30+ name = "case_insensitive_email_index" ,
31+ collation = email_collation ,
32+ unique = True ,
2933 ),
3034 ]
3135
@@ -59,8 +63,8 @@ class BeanieUserDatabase(
5963
6064 def __init__ (
6165 self ,
62- user_model : Type [UP_BEANIE ],
63- oauth_account_model : Optional [Type [BaseOAuthAccount ]] = None ,
66+ user_model : type [UP_BEANIE ],
67+ oauth_account_model : Optional [type [BaseOAuthAccount ]] = None ,
6468 ):
6569 self .user_model = user_model
6670 self .oauth_account_model = oauth_account_model
@@ -90,13 +94,13 @@ async def get_by_oauth_account(
9094 }
9195 )
9296
93- async def create (self , create_dict : Dict [str , Any ]) -> UP_BEANIE :
97+ async def create (self , create_dict : dict [str , Any ]) -> UP_BEANIE :
9498 """Create a user."""
9599 user = self .user_model (** create_dict )
96100 await user .create ()
97101 return user
98102
99- async def update (self , user : UP_BEANIE , update_dict : Dict [str , Any ]) -> UP_BEANIE :
103+ async def update (self , user : UP_BEANIE , update_dict : dict [str , Any ]) -> UP_BEANIE :
100104 """Update a user."""
101105 for key , value in update_dict .items ():
102106 setattr (user , key , value )
@@ -108,7 +112,7 @@ async def delete(self, user: UP_BEANIE) -> None:
108112 await user .delete ()
109113
110114 async def add_oauth_account (
111- self , user : UP_BEANIE , create_dict : Dict [str , Any ]
115+ self , user : UP_BEANIE , create_dict : dict [str , Any ]
112116 ) -> UP_BEANIE :
113117 """Create an OAuth account and add it to the user."""
114118 if self .oauth_account_model is None :
@@ -121,7 +125,7 @@ async def add_oauth_account(
121125 return user
122126
123127 async def update_oauth_account (
124- self , user : UP_BEANIE , oauth_account : OAP , update_dict : Dict [str , Any ]
128+ self , user : UP_BEANIE , oauth_account : OAP , update_dict : dict [str , Any ]
125129 ) -> UP_BEANIE :
126130 """Update an OAuth account on a user."""
127131 if self .oauth_account_model is None :
0 commit comments