Skip to content

Commit 2c87e51

Browse files
nanotaboadaCopilot
andcommitted
fix(api): address code review suggestions (#66)
- Add -> List[Player] return type to retrieve_all_async (List imported) - Add None guard to update_async to prevent AttributeError on missing player - Move PRAGMA calls inside try block in seed_001 so conn.close() always runs - Remove duplicate client.delete() call in DELETE test (caused 404 assertion) - Re-seed storage/players-sqlite3.db with hyphenated UUIDs (previous commit stored UUIDs without hyphens, breaking HyphenatedUUID lookups) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1a45d11 commit 2c87e51

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

services/player_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616

1717
import logging
18-
from typing import Optional
18+
from typing import List, Optional
1919
from uuid import UUID
2020

2121
from sqlalchemy import select
@@ -61,7 +61,7 @@ async def create_async(
6161
# Retrieve ---------------------------------------------------------------------
6262

6363

64-
async def retrieve_all_async(async_session: AsyncSession):
64+
async def retrieve_all_async(async_session: AsyncSession) -> List[Player]:
6565
"""
6666
Retrieves all the players from the database.
6767
@@ -133,6 +133,9 @@ async def update_async(
133133
True if the Player was updated successfully, False otherwise.
134134
"""
135135
player = await async_session.get(Player, player_id)
136+
if player is None: # pragma: no cover
137+
logger.error("Player not found for update: %s", player_id)
138+
return False
136139
player.first_name = player_model.first_name
137140
player.middle_name = player_model.middle_name
138141
player.last_name = player_model.last_name

storage/players-sqlite3.db

0 Bytes
Binary file not shown.

tests/test_main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
from uuid import UUID
2020

21-
from tests.player_stub import existing_player, nonexistent_player, unknown_player
21+
from tests.player_stub import (
22+
existing_player,
23+
nonexistent_player,
24+
unknown_player,
25+
)
2226

2327
PATH = "/players/"
2428

tools/seed_001_starting_eleven.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,11 @@ def run(db_path: Path) -> None:
249249
sys.exit(1)
250250

251251
conn = sqlite3.connect(db_path)
252-
conn.execute("PRAGMA journal_mode=WAL")
253-
conn.execute("PRAGMA foreign_keys=ON")
254252

255253
try:
254+
conn.execute("PRAGMA journal_mode=WAL")
255+
conn.execute("PRAGMA foreign_keys=ON")
256+
256257
id_type = _id_column_type(conn)
257258

258259
if id_type == "TEXT" and _already_migrated(conn):

0 commit comments

Comments
 (0)