Skip to content

Commit 16d094c

Browse files
committed
Make user_id mandatory
1 parent e3e3c1a commit 16d094c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

fastapi_users_db_dynamodb/access_token.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ async def create(self, create_dict: dict[str, Any] | AP) -> AP:
161161
token = self.access_token_table(**create_dict)
162162
else:
163163
token = create_dict
164+
if not getattr(token, "user_id", None):
165+
raise ValueError("AccessToken must implement and store value 'user_id'.")
166+
164167
try:
165168
await token.save(condition=self.access_token_table.token.does_not_exist()) # type: ignore
166169
except PutError as e:

tests/test_access_token.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ async def test_queries(
126126
access_token = await dynamodb_access_token_db.create(access_token_create)
127127
assert access_token.token == "TOKEN"
128128
assert access_token.user_id == user_id
129+
with pytest.raises(
130+
ValueError,
131+
match="AccessToken must implement and store value 'user_id'.",
132+
):
133+
access_token_create.pop("user_id")
134+
await dynamodb_access_token_db.create(access_token_create)
129135

130136
# Update
131137
new_time = now_utc()

0 commit comments

Comments
 (0)