fix: add server_default to script_template columns, refresh fork_point after commit

- script_template.py: add server_default for requires_elevation,
  is_gallery_featured, gallery_sort_order so Base.metadata.create_all
  emits proper SQL DEFAULTs (test fixtures use raw SQL INSERT)
- session_branches.py: refresh fork_point after commit so JSONB options
  field is loaded before Pydantic serialization
- test_session_branches_api.py: add status assertion on fork response

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-27 18:16:42 +00:00
parent e130976803
commit 6bf386efce
3 changed files with 6 additions and 4 deletions

View File

@@ -127,6 +127,7 @@ async def create_fork(
)
await db.commit()
await db.refresh(fork_point)
return ForkPointResponse.model_validate(fork_point)

View File

@@ -1,7 +1,7 @@
import uuid
from datetime import datetime, timezone
from typing import Optional, TYPE_CHECKING
from sqlalchemy import String, Text, DateTime, ForeignKey, Boolean, Integer, Enum as SAEnum
from sqlalchemy import String, Text, DateTime, ForeignKey, Boolean, Integer, Enum as SAEnum, text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.dialects.postgresql import UUID, JSONB
from app.core.database import Base
@@ -64,13 +64,13 @@ class ScriptTemplate(Base):
SAEnum("beginner", "intermediate", "advanced", name="script_complexity"), nullable=False, default="beginner"
)
estimated_runtime: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
requires_elevation: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
requires_elevation: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=text("false"))
requires_modules: Mapped[list] = mapped_column(JSONB, nullable=False, default=list)
version: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
is_verified: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
is_gallery_featured: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, index=True)
gallery_sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
is_gallery_featured: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=text("false"), index=True)
gallery_sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default=text("0"))
usage_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)

View File

@@ -106,6 +106,7 @@ async def test_switch_branch(client: AsyncClient, test_user, auth_headers, test_
],
},
)
assert fork_resp.status_code == 201, fork_resp.text
fork_data = fork_resp.json()
branch_b_id = fork_data["options"][1]["branch_id"]