Skip to content

Commit 2fc9f29

Browse files
Fix: Type safety and Routing issues for CI/CD. Added explicit model_validate calls and password casting.
1 parent a21b114 commit 2fc9f29

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

app/api/v1/admin/auth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ async def login_access_token(
2222
OAuth2 compatible token login, get an access token for future requests.
2323
"""
2424
user = await user_repo.get_by_email(session, email=form_data.username)
25-
if not user or not await security.verify_password(form_data.password, user.hashed_password):
25+
26+
# We explicitly cast to str() here to prevent Mypy from confusing
27+
# the ORM Column definition with the actual string value.
28+
if not user or not await security.verify_password(
29+
form_data.password, str(user.hashed_password)
30+
):
2631
raise HTTPException(
2732
status_code=status.HTTP_400_BAD_REQUEST, detail="Incorrect email or password"
2833
)

app/api/v1/content/guides.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ async def read_guides(
2626
"""
2727
Retrieve guides (Global + Private).
2828
"""
29-
return await service.get_guides(session, current_client=current_client, skip=skip, limit=limit)
29+
guides = await service.get_guides(
30+
session, current_client=current_client, skip=skip, limit=limit
31+
)
32+
return [GuideListResponse.model_validate(g) for g in guides]
3033

3134

3235
@router.post("/", response_model=GuideListResponse)
@@ -40,7 +43,10 @@ async def create_guide(
4043
"""
4144
Create a new guide.
4245
"""
43-
return await service.create_guide(session, current_client=current_client, guide_in=guide_in)
46+
guide = await service.create_guide(
47+
session, current_client=current_client, guide_in=guide_in
48+
)
49+
return GuideListResponse.model_validate(guide)
4450

4551

4652
@router.get("/{guide_id}", response_model=GuideDetailResponse)
@@ -54,13 +60,15 @@ async def read_guide(
5460
"""
5561
Get guide by ID.
5662
"""
57-
guide = await service.get_guide(session, current_client=current_client, guide_id=guide_id)
63+
guide = await service.get_guide(
64+
session, current_client=current_client, guide_id=guide_id
65+
)
5866
if not guide:
5967
raise HTTPException(
6068
status_code=status.HTTP_404_NOT_FOUND,
6169
detail="Guide not found or access denied",
6270
)
63-
return guide
71+
return GuideDetailResponse.model_validate(guide)
6472

6573

6674
@router.put("/{guide_id}", response_model=GuideListResponse)
@@ -86,4 +94,4 @@ async def update_guide(
8694
status_code=status.HTTP_404_NOT_FOUND,
8795
detail="Guide not found or access denied",
8896
)
89-
return guide
97+
return GuideListResponse.model_validate(guide)

app/api/v1/content/topics.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ async def read_topics(
2222
Retrieve topics.
2323
Clients only see Global topics or their own Private topics.
2424
"""
25-
return await service.get_topics(session, current_client=current_client, skip=skip, limit=limit)
25+
topics = await service.get_topics(
26+
session, current_client=current_client, skip=skip, limit=limit
27+
)
28+
# Explicit conversion for Mypy
29+
return [TopicResponse.model_validate(t) for t in topics]
2630

2731

2832
@router.post("/", response_model=TopicResponse)
@@ -36,7 +40,10 @@ async def create_topic(
3640
"""
3741
Create a new topic.
3842
"""
39-
return await service.create_topic(session, current_client=current_client, topic_in=topic_in)
43+
topic = await service.create_topic(
44+
session, current_client=current_client, topic_in=topic_in
45+
)
46+
return TopicResponse.model_validate(topic)
4047

4148

4249
@router.put("/{topic_id}", response_model=TopicResponse)
@@ -59,7 +66,7 @@ async def update_topic(
5966
status_code=status.HTTP_404_NOT_FOUND,
6067
detail="Topic not found or access denied",
6168
)
62-
return topic
69+
return TopicResponse.model_validate(topic)
6370

6471

6572
@router.get("/{topic_id}", response_model=TopicDetail)
@@ -73,10 +80,12 @@ async def read_topic(
7380
"""
7481
Get topic by ID.
7582
"""
76-
topic = await service.get_topic(session, current_client=current_client, topic_id=topic_id)
83+
topic = await service.get_topic(
84+
session, current_client=current_client, topic_id=topic_id
85+
)
7786
if not topic:
7887
raise HTTPException(
7988
status_code=status.HTTP_404_NOT_FOUND,
8089
detail="Topic not found or access denied",
8190
)
82-
return topic
91+
return TopicDetail.model_validate(topic)

0 commit comments

Comments
 (0)