Fix: Load user relationship in listings API to prevent 500 error
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled

This commit is contained in:
2025-12-16 15:16:36 +01:00
parent dfdee7512a
commit 114fc3d9d6

View File

@ -27,6 +27,7 @@ from fastapi import APIRouter, Depends, Query, HTTPException, Request
from pydantic import BaseModel, Field, EmailStr
from sqlalchemy import select, func, and_
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from app.database import get_db
from app.api.deps import get_current_user, get_current_user_optional
@ -284,7 +285,7 @@ async def browse_listings(
db: AsyncSession = Depends(get_db),
):
"""Browse active domain listings (public)."""
query = select(DomainListing).where(
query = select(DomainListing).options(selectinload(DomainListing.user)).where(
DomainListing.status == ListingStatus.ACTIVE.value
)
@ -413,7 +414,9 @@ async def get_listing_by_slug(
):
"""Get listing details by slug (public)."""
result = await db.execute(
select(DomainListing).where(
select(DomainListing)
.options(selectinload(DomainListing.user))
.where(
and_(
DomainListing.slug == slug,
DomainListing.status == ListingStatus.ACTIVE.value,