Skip to content

Commit 340111d

Browse files
fix: address PR review — datetime handling, deferred fields, noqa stripping
- Fix _build_dashboard passing datetime to _parse_iso (expects str) - Add ImplRepository.get_code() that only undefers code field - Use get_code() in /specs/{id}/{lib}/code endpoint (avoids loading review fields) - Apply strip_noqa_comments to POTD code response for consistency - Fix docstring in get_by_id() to match actual undefer behavior - Remove stale changelog/comparison references from module docstring - Update tests to use get_code mock Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e820d4 commit 340111d

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

api/routers/insights.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
- Dashboard: Rich platform statistics and visualizations
66
- Plot of the Day: Daily featured high-quality implementation
77
- Related Plots: Tag-based similarity recommendations
8-
- Library Comparison: Head-to-head library analysis
9-
- Changelog: Recent additions and updates activity feed
108
"""
119

1210
from __future__ import annotations
@@ -24,6 +22,7 @@
2422
from core.constants import SUPPORTED_LIBRARIES
2523
from core.database import ImplRepository, SpecRepository
2624
from core.database.connection import get_db_context
25+
from core.utils import strip_noqa_comments
2726

2827

2928
router = APIRouter(prefix="/insights", tags=["insights"])
@@ -257,8 +256,8 @@ async def _build_dashboard(repo: SpecRepository, impl_repo: ImplRepository) -> D
257256
)
258257
)
259258

260-
# Timeline from generated_at
261-
gen_dt = _parse_iso(impl.generated_at)
259+
# Timeline from generated_at (datetime field, not string)
260+
gen_dt = impl.generated_at
262261
if gen_dt:
263262
monthly_counts[gen_dt.strftime("%Y-%m")] += 1
264263

@@ -397,7 +396,7 @@ async def _build_potd(spec_repo: SpecRepository, impl_repo: ImplRepository) -> P
397396
quality_score=quality_score,
398397
preview_url=preview_url,
399398
image_description=full_impl.review_image_description if full_impl else None,
400-
code=full_impl.code if full_impl else None,
399+
code=strip_noqa_comments(full_impl.code) if full_impl and full_impl.code else None,
401400
date=today,
402401
)
403402

api/routers/specs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def get_impl_code(spec_id: str, library: str, db: AsyncSession = Depends(r
143143
return cached
144144

145145
repo = ImplRepository(db)
146-
impl = await repo.get_by_spec_and_library(spec_id, library)
146+
impl = await repo.get_code(spec_id, library)
147147

148148
if not impl or not impl.code:
149149
raise_not_found("Implementation code", f"{spec_id}/{library}")

core/database/repositories.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ class SpecRepository(BaseRepository[Spec]):
114114
async def get_by_id(self, spec_id: str) -> Optional[Spec]:
115115
"""Get a spec by ID with implementations and library info.
116116
117-
Note: Heavy deferred fields (code, review_criteria_checklist) are NOT loaded.
118-
Use ImplRepository.get_by_spec_and_library() for full impl details.
119-
review_image_description IS loaded (small, needed for detail display).
117+
Loads review_image_description and review_criteria_checklist (needed for detail display).
118+
Code and tested remain deferred — use /specs/{id}/{lib}/code for code.
120119
"""
121120
result = await self.session.execute(
122121
select(Spec)
@@ -231,6 +230,13 @@ async def get_by_library(self, library_id: str) -> list[Impl]:
231230
)
232231
return list(result.scalars().all())
233232

233+
async def get_code(self, spec_id: str, library_id: str) -> Optional[Impl]:
234+
"""Get a specific implementation with only the code field undeferred."""
235+
result = await self.session.execute(
236+
select(Impl).where(Impl.spec_id == spec_id, Impl.library_id == library_id).options(undefer(Impl.code))
237+
)
238+
return result.scalar_one_or_none()
239+
234240
async def get_by_spec_and_library(self, spec_id: str, library_id: str) -> Optional[Impl]:
235241
"""Get a specific implementation by spec and library (includes all deferred fields)."""
236242
result = await self.session.execute(

tests/unit/api/test_routers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ def test_code_with_db(self, client: TestClient) -> None:
15841584
mock_impl = MagicMock()
15851585
mock_impl.code = "import matplotlib.pyplot as plt\nplt.plot([1,2,3])"
15861586
mock_impl_repo = MagicMock()
1587-
mock_impl_repo.get_by_spec_and_library = AsyncMock(return_value=mock_impl)
1587+
mock_impl_repo.get_code = AsyncMock(return_value=mock_impl)
15881588

15891589
with (
15901590
patch(DB_CONFIG_PATCH, return_value=True),
@@ -1602,7 +1602,7 @@ def test_code_with_db(self, client: TestClient) -> None:
16021602
def test_code_not_found(self, client: TestClient) -> None:
16031603
"""Code endpoint should return 404 when implementation not found."""
16041604
mock_impl_repo = MagicMock()
1605-
mock_impl_repo.get_by_spec_and_library = AsyncMock(return_value=None)
1605+
mock_impl_repo.get_code = AsyncMock(return_value=None)
16061606

16071607
with (
16081608
patch(DB_CONFIG_PATCH, return_value=True),

0 commit comments

Comments
 (0)