Skip to content

Commit f272348

Browse files
committed
fix typing and ruff linting, plus issue with auth model pages
1 parent ca99546 commit f272348

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

crudadmin/admin_interface/model_view.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BulkDeleteRequest(BaseModel):
4545

4646

4747
class ModelView:
48-
"""
48+
r"""
4949
View class for managing CRUD operations and UI for database models in FastAPI admin interface.
5050
5151
Features:
@@ -754,7 +754,10 @@ async def get_model_admin_page_inner(
754754
request: Request,
755755
admin_db: AsyncSession = Depends(self.db_config.get_admin_db),
756756
app_db: AsyncSession = Depends(
757-
cast(Callable[..., AsyncGenerator[AsyncSession, None]], self.db_config.get_app_session())
757+
cast(
758+
Callable[..., AsyncGenerator[AsyncSession, None]],
759+
self.db_config.get_app_session(),
760+
)
758761
),
759762
) -> Response:
760763
"""Display the model list page, allowing pagination, sorting, and searching."""

crudadmin/admin_token/service.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from datetime import datetime, timedelta, timezone
3-
from typing import Optional
3+
from typing import Any, Dict, Optional, cast
44

55
from jose import JWTError, jwt
66
from sqlalchemy.ext.asyncio import AsyncSession
@@ -81,9 +81,10 @@ async def verify_token(
8181
self.SECRET_KEY,
8282
algorithms=[self.ALGORITHM],
8383
)
84-
username_or_email: str = payload.get("sub")
85-
if username_or_email is None:
86-
logger.warning("No username/email found in token")
84+
payload_dict = cast(Dict[str, Any], payload)
85+
username_or_email = payload_dict.get("sub")
86+
if not isinstance(username_or_email, str):
87+
logger.warning("No valid username/email found in token")
8788
return None
8889

8990
logger.info("Token verified successfully")
@@ -109,7 +110,12 @@ async def blacklist_token(
109110
self.SECRET_KEY,
110111
algorithms=[self.ALGORITHM],
111112
)
112-
expires_at = datetime.fromtimestamp(payload.get("exp"))
113+
payload_dict = cast(Dict[str, Any], payload)
114+
exp = payload_dict.get("exp")
115+
if not isinstance(exp, (int, float)):
116+
logger.error("Invalid expiration in token")
117+
return
118+
expires_at = datetime.fromtimestamp(exp)
113119
await self.crud_token_blacklist.create(
114120
db,
115121
object=AdminTokenBlacklistCreate(token=token, expires_at=expires_at),

0 commit comments

Comments
 (0)