fix: manual population of show relationships in response
Some checks failed
Deploy Fediversion / deploy (push) Failing after 0s

This commit is contained in:
fullsizemalt 2025-12-31 18:40:46 -08:00
parent 6b9d778b4d
commit 7edec61af1

View file

@ -4,7 +4,7 @@ from sqlmodel import Session, select
from sqlalchemy import func from sqlalchemy import func
from database import get_session from database import get_session
from models import Show, Tag, EntityTag, Vertical, UserVerticalPreference from models import Show, Tag, EntityTag, Vertical, UserVerticalPreference
from schemas import ShowCreate, ShowRead, ShowUpdate, TagRead, PaginatedResponse, PaginationMeta from schemas import ShowCreate, ShowRead, ShowUpdate, TagRead, PaginatedResponse, PaginationMeta, VerticalSimple, VenueRead, TourRead
from auth import get_current_user, get_current_user_optional from auth import get_current_user, get_current_user_optional
router = APIRouter(prefix="/shows", tags=["shows"]) router = APIRouter(prefix="/shows", tags=["shows"])
@ -109,8 +109,25 @@ def read_shows(
shows = session.exec(query.offset(offset).limit(limit)).all() shows = session.exec(query.offset(offset).limit(limit)).all()
# Manual population to ensure relationships are serialized
# (Pydantic v2/SQLModel can be tricky with ORM relationships sometimes)
response_shows = []
for show in shows:
# Convert ORM object to ShowRead explicitly
# We use model_validate to get base fields, then set relationships
s_read = ShowRead.model_validate(show)
if show.vertical:
s_read.vertical = VerticalSimple.model_validate(show.vertical)
if show.venue:
s_read.venue = VenueRead.model_validate(show.venue)
if show.tour:
s_read.tour = TourRead.model_validate(show.tour)
response_shows.append(s_read)
return PaginatedResponse( return PaginatedResponse(
data=shows, data=response_shows,
meta=PaginationMeta(total=total, limit=limit, offset=offset) meta=PaginationMeta(total=total, limit=limit, offset=offset)
) )