Skip to content

fix(models): a second dataset's first model upload 500s — matching_models' unique key is org-scoped, not dataset-scoped #1444

Done

Description

@athvin

Found while setting up #558 on er-dev (2026-11-29).

POST /v1/orgs/p3live/datasets/spill10m/models/versions with the default name returned 500:

duplicate key value violates unique constraint "matching_models_org_name_version"
Key (org_id, name, version)=(01a1ad41-…, default, 1) already exists.

The org's default dataset already had default v1. The version allocator numbers per dataset, but entities/matching_model/entity.yaml declares the unique index on (org_id, name, version). So every dataset after an org's first collides on its first upload under the default name. That covers the starter seed, a train, and any upload that omits name. Uploading under another name works around it.

Check the same scoping in activation and the active read: one active version per name must mean per (dataset, name), or activating a model in one dataset could archive another dataset's.

Done when:

  • the key and the allocator agree on (org, dataset, name, version);
  • a second dataset can seed, train and upload under default;
  • activating in one dataset leaves the other's active model alone;
  • a pg test proves all three;
  • a 500 can't come from this path (a conflict is a 409, never a raw db error).

Activity

  1. added
    followup
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    followup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions