Skip to content

Allow passing member dataset ids when creating a Collection #49

Description

@NathanCummings

Summary

Let a Collection be created and populated in a single request by accepting an optional list of member dataset ids on create. Today, membership is add-one-at-a-time only, so creating a populated collection takes 1 + N requests.

Background

  • CollectionCreate (app/models/collection.py) has no way to include datasets — its fields are name / device_name / access_level / root_url / activity_id / shot_id / origin / required_scopes / allowed_idps.
  • The only way to add members is the per-dataset endpoint POST /collections/{collection_id}/datasets/{dataset_id} (bodyless; CollectionService.add_dataset takes a single dataset_id). There is no bulk path.
  • So clients (and the docs example) must create the collection, then loop the single-POST call once per dataset.

Change

  • app/models/collection.py — add to CollectionCreate: dataset_ids: list[int] | None = None.
  • CollectionService create path — after creating the collection, add each id in dataset_ids as a member, reusing the existing add_dataset validation (dataset exists, access authorised, dedupe). Recommend all-or-nothing semantics: if any id is missing/inaccessible, reject the whole request so you never get a half-populated collection. (Document whichever semantics are chosen.)
  • Keep the existing single-POST membership endpoint for incremental add/remove after creation.
  • Optional / decide if in scope: a companion bulk-add-to-existing endpoint (POST /collections/{id}/datasets with a list body) so the same convenience exists for already-created collections. The user's request was specifically about the create request, so this can be split out.

Docs & demo

  • Update the Collection example to pass dataset_ids in the create call (replacing the per-dataset loop). File is docs/data-model/collection.md on the docs/examples-in-concepts branch, or docs/concepts/data-model.md on main — edit whichever exists.
  • Optionally switch demo/seed_metadata.py collection creation to the one-call form.

Acceptance criteria

  • POST /collections with {"name": ..., "dataset_ids": [1, 2, 3]} creates the collection and adds those datasets as members in one call.
  • An invalid or inaccessible dataset id is rejected per chosen semantics (recommended: whole request fails, no partial collection).
  • Each dataset add still respects the caller's authorization (reuse add_dataset checks).
  • Existing single-POST membership endpoint unchanged.
  • Collection docs example updated to the one-call form.
  • uv run --all-extras pytest green; prek run --all-files clean.

Notes

  • Branch off main. Standalone change.

Migrated from the internal tracker, where it was #26, opened 2026-07-24.

Activity

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

    apiHTTP API surfacedxDeveloper experienceenhancementNew feature or requestpriority: lowWhen convenient

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions