Files
nuzlocke-tracker/.beans/nuzlocke-tracker-9xac--fix-stale-postgresql-enum-causing-test-failures.md
Julian Tabel afd1c2543a
Some checks failed
CI / backend-tests (pull_request) Failing after 32s
CI / frontend-tests (pull_request) Failing after 29s
chore: update bean
2026-03-21 11:30:09 +01:00

2.0 KiB

title, status, type, priority, created_at, updated_at
title status type priority created_at updated_at
Fix stale PostgreSQL enum causing test failures completed bug normal 2026-03-21T10:27:53Z 2026-03-21T10:29:33Z

Problem

The backend smoke tests fail with:

sqlalchemy.exc.DBAPIError: invalid input value for enum run_visibility: "public"

This happens during Base.metadata.create_all in the engine fixture (backend/tests/conftest.py:27).

Root Cause

The engine fixture only calls create_all during setup and drop_all during teardown. If a previous test run was interrupted before teardown, the run_visibility PostgreSQL enum type persists in the test database with stale/incorrect values. On the next run, create_all (with checkfirst=True default) sees the enum exists and skips recreating it, but the existing enum lacks valid values, causing the DEFAULT 'public' to fail.

PostgreSQL native enum types are not automatically dropped with DROP TABLE — they require explicit DROP TYPE.

Fix

In the engine fixture at backend/tests/conftest.py:23-31, add Base.metadata.drop_all before create_all to ensure a clean slate:

@pytest.fixture(scope="session")
async def engine():
    eng = create_async_engine(TEST_DATABASE_URL, echo=False)
    async with eng.begin() as conn:
        await conn.run_sync(Base.metadata.drop_all)   # <-- add this
        await conn.run_sync(Base.metadata.create_all)
    yield eng
    async with eng.begin() as conn:
        await conn.run_sync(Base.metadata.drop_all)
    await eng.dispose()

Checklist

  • Add drop_all before create_all in the engine fixture (backend/tests/conftest.py)
  • Verify tests pass with pytest backend/tests/test_smoke.py

Summary of Changes

Added drop_all before create_all in the test engine fixture to ensure stale PostgreSQL enum types are cleared before recreating the schema. This prevents test failures when a previous test run was interrupted before cleanup.