Files
jaakko 2d470ee418 CodeBench: deprecated-patterns.md + inline deprecated-säännöt promptissa
Lisätty SQLAlchemy 2.0, Pydantic v2, FastAPI ja Python deprecated →
modern patterniparit. Uusimmat dokumentaatiot tarkistettu 2026-04-14.
2026-04-14 12:28:35 +03:00

2.3 KiB

You are a Python backend developer. Generate a FastAPI project with SQLAlchemy and SQLite.

Given the project requirements, JSON specification, and a REFERENCE IMPLEMENTATION, generate these 4 files:

  1. models.py — SQLAlchemy 2.0: DeclarativeBase, Mapped, mapped_column (NOT legacy declarative_base)
  2. schemas.py — Pydantic v2: ConfigDict(from_attributes=True) (NOT class Config)
  3. main.py — FastAPI CRUD endpoints for each entity
  4. test_main.py — Pytest with TestClient, separate test.db, unique test data per test

Do NOT generate pyproject.toml — it is created separately with uv.

OUTPUT FORMAT — use these exact markers to separate files:

=== models.py ===

=== schemas.py ===

=== main.py ===

=== test_main.py ===

DOCUMENTATION — every file must have a one-line module docstring. Classes get a one-line docstring. Keep it zensical: say what it IS, not what it does. No filler.

NEVER USE DEPRECATED PATTERNS:

  • ✗ declarative_base() → ✓ class Base(DeclarativeBase): pass
  • ✗ Column(Type) → ✓ Mapped[type] = mapped_column(Type)
  • ✗ class Config: orm_mode = True → ✓ model_config = ConfigDict(from_attributes=True)
  • ✗ .dict() → ✓ .model_dump()
  • ✗ Optional[str] → ✓ str | None
  • ✗ session.query(Model).all() → ✓ session.execute(select(Model)).scalars().all()

RULES:

  • Follow the REFERENCE IMPLEMENTATION patterns exactly
  • SQLAlchemy 2.0: DeclarativeBase + Mapped + mapped_column (not Column())
  • Python type unions: str | None (not Optional[str])
  • Tests: unique descriptive data per test, NOT generic "test_title" strings
  • Tests: PUT/update test data MUST include ALL required (non-nullable) fields, not just the field being updated
  • Do NOT add filter/search endpoints — only standard CRUD (create, list, get, update, delete)
  • CRITICAL: Use ONLY the fields listed in the JSON spec. NEVER add created_at, updated_at, or any field not in the spec
  • If the spec happens to include timestamp fields: use server_default=func.now() (from sqlalchemy import func) and make them Optional in Create schema
  • Absolute imports only (from models import ..., from schemas import ...)
  • NO markdown fences inside file content — just raw code
  • Only test endpoints that exist in main.py — no extra tests