- Drop Product.personal_rating from model, API schemas, and all frontend views (list table, detail view, quick-edit form, new-product form) - Extract get_or_404 into backend/innercontext/api/utils.py; remove five duplicate copies from individual API modules - Fix all ty type errors: generic get_or_404 with TypeVar, cast() in coerce_effect_profile validator, col() for ilike on SQLModel column, dict[str, Any] annotation in test helper, ty: ignore for CORSMiddleware Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
13 lines
347 B
Python
13 lines
347 B
Python
from typing import TypeVar
|
|
|
|
from fastapi import HTTPException
|
|
from sqlmodel import Session
|
|
|
|
_T = TypeVar("_T")
|
|
|
|
|
|
def get_or_404(session: Session, model: type[_T], record_id: object) -> _T:
|
|
obj = session.get(model, record_id)
|
|
if obj is None:
|
|
raise HTTPException(status_code=404, detail=f"{model.__name__} not found")
|
|
return obj
|