@@ -61,14 +61,14 @@ def __init__(
6161 self ._resource = dynamodb_resource
6262
6363 @asynccontextmanager
64- async def _table (self ):
64+ async def _table (self , table_name : str ):
6565 """Async context manager that yields a Table object."""
6666 if self ._resource is not None :
67- table = await self ._resource .Table (self . table_name )
67+ table = await self ._resource .Table (table_name )
6868 yield table
6969 else :
7070 async with self .session .resource ("dynamodb" ) as dynamodb :
71- table = await dynamodb .Table (self . table_name )
71+ table = await dynamodb .Table (table_name )
7272 yield table
7373
7474 def _item_to_access_token (self , item : dict [str , Any ] | None ) -> AP | None :
@@ -100,7 +100,7 @@ async def get_by_token(
100100 self , token : str , max_age : datetime | None = None
101101 ) -> AP | None :
102102 """Retrieve an access token by token string."""
103- async with self ._table () as table :
103+ async with self ._table (self . table_name ) as table :
104104 resp = await table .get_item (Key = {"token" : self ._ensure_token (token )})
105105 item = resp .get ("Item" )
106106
@@ -125,7 +125,7 @@ async def create(self, create_dict: dict[str, Any]) -> AP:
125125 if isinstance (item .get ("user_id" ), uuid .UUID ):
126126 item ["user_id" ] = str (item ["user_id" ])
127127
128- async with self ._table () as table :
128+ async with self ._table (self . table_name ) as table :
129129 await table .put_item (Item = item )
130130
131131 resp = await table .get_item (Key = {"token" : item ["token" ]})
@@ -153,7 +153,7 @@ async def update(self, access_token: AP, update_dict: dict[str, Any]) -> AP:
153153 if isinstance (token_dict .get ("created_at" ), datetime ):
154154 token_dict ["created_at" ] = token_dict ["created_at" ].isoformat ()
155155
156- async with self ._table () as table :
156+ async with self ._table (self . table_name ) as table :
157157 await table .put_item (Item = token_dict )
158158
159159 resp = await table .get_item (Key = {"token" : token_dict ["token" ]})
@@ -172,5 +172,5 @@ async def delete(self, access_token: AP) -> None:
172172 if token is None :
173173 raise ValueError ("access_token has no 'token' field" )
174174
175- async with self ._table () as table :
175+ async with self ._table (self . table_name ) as table :
176176 await table .delete_item (Key = {"token" : self ._ensure_token (token )})
0 commit comments