Fix test factory Provider collision from ingestion-cascade tests
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s

tests/integration/factories.py:make_provider did a raw INSERT
assuming no "tmdb" Provider row existed yet. That held as long as
every test used the db_session fixture's isolated, rolled-back
transaction -- but the new ingestion-cascade tests call
get_or_create_ingestion_job, which really commits via
session_scope()'s own connection, outside that per-test isolation.
Once that ran, every later test using the raw-insert factory hit
"duplicate key value violates unique constraint uq_providers_slug".

Fixed by using the app's own get_or_create_provider in the factory
instead of a bare insert, which is also just correct: provider slugs
are unique in production too, so the test helper should behave the
same way real ingestion code does rather than assume a pristine table.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
NixReaper
2026-09-05 02:21:43 -05:00
co-authored by Claude Sonnet 5
parent b4d1e8f755
commit 64169c4aee
+6 -4
View File
@@ -14,13 +14,15 @@ from app.models.genre import Genre, MovieGenre
from app.models.movie import Movie
from app.models.person import Person
from app.models.provider import Provider
from app.repositories.provider_repository import get_or_create_provider
async def make_provider(session: AsyncSession, slug: str = "tmdb") -> Provider:
provider = Provider(slug=slug, name=slug.upper())
session.add(provider)
await session.flush()
return provider
# get_or_create, not a raw insert: some tests (e.g. the ingestion
# cascade ones) create a real "tmdb" Provider row via session_scope()'s
# own connection, outside this test's rolled-back transaction, so it
# can already exist here regardless of db_session's per-test isolation.
return await get_or_create_provider(session, slug, slug.upper())
async def make_movie(