fix: 도메인 예외 롤백 로깅 개선 및 영상 생성 템플릿 배정 일관성 수정

- get_session에서 SocialException/DashboardException을 별도로 처리하여
  정상 플로우인 도메인 예외는 ERROR traceback 없이 warning 롤백 로그만 남기도록 수정
- generate_video 호출 시 CreatomateService에 project_id를 전달하여,
  미매핑 업종(general 등)의 템플릿 분배가 사전 이미지 배정 단계와
  동일한 템플릿을 사용하도록 일관성 확보
This commit is contained in:
김성경 2026-07-27 11:21:01 +09:00
parent 73b05f5cca
commit cb8485ecd5
2 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,8 @@ from fastapi import HTTPException
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import DeclarativeBase
from app.dashboard.exceptions import DashboardException
from app.social.exceptions import SocialException
from app.utils.logger import get_logger
from config import db_settings
@ -137,6 +139,16 @@ async def get_session() -> AsyncGenerator[AsyncSession, None]:
yield session
except HTTPException:
raise
except (SocialException, DashboardException) as e:
# 전역 exception handler가 응답으로 변환하는 도메인 예외.
# 정상 플로우이므로 ERROR traceback 없이 롤백만 수행.
await session.rollback()
logger.warning(
f"[get_session] ROLLBACK - handled domain error: "
f"{type(e).__name__}: {e}, "
f"duration: {(time.perf_counter() - start_time)*1000:.1f}ms"
)
raise
except Exception as e:
await session.rollback()
logger.error(traceback.format_exc())

View File

@ -356,6 +356,9 @@ async def generate_video(
creatomate_service = CreatomateService(
orientation=orientation,
industry=industry,
# 미매핑 업종(general 등)은 project_id % len(VST_LIST)로 템플릿을 분배하므로,
# 사전 이미지 배정 단계(creative_assets_task)와 동일 템플릿을 받으려면 필수
project_id=project_id,
)
logger.debug(
f"[generate_video] Using template_id: {creatomate_service.template_id}, (song duration: {song_duration})"