Skip to content

Commit b53eb2a

Browse files
committed
.
1 parent d14c83c commit b53eb2a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

fastapi_users_db_dynamodb/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ async def get(
249249
self.oauth_account_table_name, self._resource_region
250250
) as oauth_table:
251251
resp = await oauth_table.scan(
252-
FilterExpression=Attr("user_id").eq(id_str)
252+
FilterExpression=Attr("user_id").eq(id_str),
253+
ConsistentRead=instant_update,
253254
)
254255
accounts = resp.get("Items", [])
255256
user.oauth_accounts = [ # type: ignore
@@ -258,13 +259,18 @@ async def get(
258259

259260
return user
260261

261-
async def get_by_email(self, email: str) -> UP | None:
262+
async def get_by_email(
263+
self,
264+
email: str,
265+
instant_update: bool = False,
266+
) -> UP | None:
262267
"""Get a user by email (case-insensitive: emails are stored lowercased)."""
263268
email_norm = email.lower()
264269
async with self._table(self.user_table_name, self._resource_region) as table:
265270
resp = await table.scan(
266271
FilterExpression=Attr("email").eq(email_norm),
267272
Limit=1,
273+
ConsistentRead=instant_update,
268274
)
269275
items = resp.get("Items", [])
270276
if not items:
@@ -280,7 +286,8 @@ async def get_by_email(self, email: str) -> UP | None:
280286
self.oauth_account_table_name, self._resource_region
281287
) as oauth_table:
282288
resp = await oauth_table.scan(
283-
FilterExpression=Attr("user_id").eq(user_id)
289+
FilterExpression=Attr("user_id").eq(user_id),
290+
ConsistentRead=instant_update,
284291
)
285292
accounts = resp.get("Items", [])
286293
user.oauth_accounts = [ # type: ignore
@@ -289,7 +296,12 @@ async def get_by_email(self, email: str) -> UP | None:
289296

290297
return user
291298

292-
async def get_by_oauth_account(self, oauth: str, account_id: str) -> UP | None:
299+
async def get_by_oauth_account(
300+
self,
301+
oauth: str,
302+
account_id: str,
303+
instant_update: bool = False,
304+
) -> UP | None:
293305
"""Find a user by oauth provider and provider account id."""
294306
if self.oauth_account_table is None or self.oauth_account_table_name is None:
295307
raise NotImplementedError()
@@ -301,6 +313,7 @@ async def get_by_oauth_account(self, oauth: str, account_id: str) -> UP | None:
301313
FilterExpression=Attr("oauth_name").eq(oauth)
302314
& Attr("account_id").eq(account_id),
303315
Limit=1,
316+
ConsistentRead=instant_update,
304317
)
305318
items = resp.get("Items", [])
306319
if not items:

0 commit comments

Comments
 (0)