Skip to content
This repository was archived by the owner on Jun 13, 2026. It is now read-only.
This repository was archived by the owner on Jun 13, 2026. It is now read-only.

sync_creatives should not create assignments for creatives that failed validation #663

Description

@bokelley

From local storefront E2E against ghcr.io/bokelley/salesagent:latest (image id 8d9a7d94b344), sync_creatives can return INTERNAL_ERROR when a creative fails validation but the request also includes assignments.

Repro shape:

  • create_media_buy succeeds and returns a package.
  • sync_creatives sends one new creative with an unsupported format_id.agent_url, plus an assignment to the package.
  • Creative validation fails, so no row is inserted into creatives.
  • _process_assignments still inserts creative_assignments for that creative.

Observed DB error:

psycopg2.errors.ForeignKeyViolation: insert or update on table "creative_assignments" violates foreign key constraint "fk_creative_assignments_creative_composite"
DETAIL: Key (creative_id, tenant_id, principal_id)=(strict-e2e-creative-..., tenant_5b0bec3d, principal_1951e7c9) is not present in table "creatives".

Expected:

  • If a creative fails validation, assignment processing should skip it and return a per-creative action: failed response with an assignment/validation error.
  • No FK violation or INTERNAL_ERROR should leak to the buyer.

Likely area: src/core/tools/creatives/_sync.py processes assignments after creative processing, and _assignments.py does not appear to check that the creative exists before upserting the assignment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions