Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions codewiki/src/fe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from datetime import datetime
from typing import Optional
from typing import Optional, Any, Dict
from dataclasses import dataclass
from pydantic import BaseModel, HttpUrl

Expand Down Expand Up @@ -44,6 +44,42 @@ class JobStatus:
main_model: Optional[str] = None
commit_id: Optional[str] = None

def to_dict(self) -> Dict[str, Any]:
"""Serialize this JobStatus to a plain dict."""
return {
"job_id": self.job_id,
"repo_url": self.repo_url,
"status": self.status,
"created_at": self.created_at.isoformat() if self.created_at else None,
"started_at": self.started_at.isoformat() if self.started_at else None,
"completed_at": self.completed_at.isoformat() if self.completed_at else None,
"error_message": self.error_message,
"progress": self.progress,
"docs_path": self.docs_path,
"main_model": self.main_model,
"commit_id": self.commit_id,
}

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "JobStatus":
"""Deserialize a JobStatus from a plain dict."""
created_at = data.get("created_at")
started_at = data.get("started_at")
completed_at = data.get("completed_at")
return cls(
job_id=data["job_id"],
repo_url=data["repo_url"],
status=data["status"],
created_at=datetime.fromisoformat(created_at) if isinstance(created_at, str) else created_at,
started_at=datetime.fromisoformat(started_at) if isinstance(started_at, str) else started_at,
completed_at=datetime.fromisoformat(completed_at) if isinstance(completed_at, str) else completed_at,
error_message=data.get("error_message"),
progress=data.get("progress", ""),
docs_path=data.get("docs_path"),
main_model=data.get("main_model"),
commit_id=data.get("commit_id"),
)


@dataclass

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 CacheEntry dataclass lacks to_dict/from_dict; serialization duplicated in CacheManager

Added to_dict/from_dict methods to the CacheEntry dataclass (codewiki/src/fe/models.py, lines within the CacheEntry class), explicitly handling the five named fields (repo_url, repo_url_hash, docs_path, created_at, last_accessed) including datetime ISO conversion. As with JobStatus, cache_manager.py's load_cache_index/save_cache_index were not touched since only models.py was in scope; a complete fix requires updating cache_manager.py to call CacheEntry.to_dict()/CacheEntry.from_dict() instead of manual dict construction.

πŸ€– Prompt for AI agents
In codewiki/src/fe/models.py around line 48, review and complete this code-review fix: CacheEntry dataclass lacks to_dict/from_dict; serialization duplicated in CacheManager.
What the draft fix changed: Added `to_dict`/`from_dict` methods to the `CacheEntry` dataclass (codewiki/src/fe/models.py, lines within the `CacheEntry` class), explicitly handling the five named fields (`repo_url`, `repo_url_hash`, `docs_path`, `created_at`, `last_accessed`) including datetime ISO conversion. As with JobStatus, cache_manager.py's load_cache_index/save_cache_index were not touched since only models.py was in scope; a complete fix requires updating cache_manager.py to call `CacheEntry.to_dict()`/`CacheEntry.from_dict()` instead of manual dict construction.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

class CacheEntry:
Comment on lines 44 to 85

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 JobStatus, CacheEntry dataclasses lack to_dict/from_dict methods

Added to_dict/from_dict methods to the JobStatus dataclass (codewiki/src/fe/models.py, lines within the JobStatus class). to_dict explicitly maps all fields to a plain dict (converting datetimes to ISO strings), and from_dict reconstructs a JobStatus from a dict (parsing ISO datetime strings back). This is a self-contained addition to models.py; cache_manager.py was not modified (out of scope for this file-only fix), so the reviewer should follow up there to replace the hand-rolled logic with calls to these new methods.

πŸ€– Prompt for AI agents
In codewiki/src/fe/models.py around line 32, review and complete this code-review fix: JobStatus, CacheEntry dataclasses lack to_dict/from_dict methods.
What the draft fix changed: Added `to_dict`/`from_dict` methods to the `JobStatus` dataclass (codewiki/src/fe/models.py, lines within the `JobStatus` class). `to_dict` explicitly maps all fields to a plain dict (converting datetimes to ISO strings), and `from_dict` reconstructs a `JobStatus` from a dict (parsing ISO datetime strings back). This is a self-contained addition to models.py; cache_manager.py was not modified (out of scope for this file-only fix), so the reviewer should follow up there to replace the hand-rolled logic with calls to these new methods.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand All @@ -52,4 +88,27 @@ class CacheEntry:
repo_url_hash: str
docs_path: str
created_at: datetime
last_accessed: datetime
last_accessed: datetime

def to_dict(self) -> Dict[str, Any]:
"""Serialize this CacheEntry to a plain dict."""
return {
"repo_url": self.repo_url,
"repo_url_hash": self.repo_url_hash,
"docs_path": self.docs_path,
"created_at": self.created_at.isoformat() if self.created_at else None,
"last_accessed": self.last_accessed.isoformat() if self.last_accessed else None,
}

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "CacheEntry":
"""Deserialize a CacheEntry from a plain dict."""
created_at = data.get("created_at")
last_accessed = data.get("last_accessed")
return cls(
repo_url=data["repo_url"],
repo_url_hash=data["repo_url_hash"],
docs_path=data["docs_path"],
created_at=datetime.fromisoformat(created_at) if isinstance(created_at, str) else created_at,
last_accessed=datetime.fromisoformat(last_accessed) if isinstance(last_accessed, str) else last_accessed,
)