fix: manual population of show relationships in response
Some checks failed
Deploy Fediversion / deploy (push) Failing after 0s
Some checks failed
Deploy Fediversion / deploy (push) Failing after 0s
This commit is contained in:
parent
6b9d778b4d
commit
7edec61af1
1 changed files with 19 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ from sqlmodel import Session, select
|
|||
from sqlalchemy import func
|
||||
from database import get_session
|
||||
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
|
||||
|
||||
router = APIRouter(prefix="/shows", tags=["shows"])
|
||||
|
|
@ -109,8 +109,25 @@ def read_shows(
|
|||
|
||||
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(
|
||||
data=shows,
|
||||
data=response_shows,
|
||||
meta=PaginationMeta(total=total, limit=limit, offset=offset)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue