Skip to content

Feature nwp 2119 sample run association and bulk submission#216

Merged
golharam merged 4 commits intomainfrom
feature-NWP-2119-sample-run-association-and-bulk-submission
Apr 8, 2026
Merged

Feature nwp 2119 sample run association and bulk submission#216
golharam merged 4 commits intomainfrom
feature-NWP-2119-sample-run-association-and-bulk-submission

Conversation

@accumb3ns
Copy link
Copy Markdown
Contributor

this PR adds the ability to associate a sample with a sequencing run at creation time, rather than requiring a second API call to do so. also - because we want a samplesheet to atomically succeed or fail, we add a bulk endpoint that validates and creates all records in a single transaction, reducing calls from 2N for N samples to 1; this is generalized and can be used for posting manifests also. tests are added for the bulk endpoint.

there is one minor bugfix - previously, for a single sample submission, if there was an error with opensearch indexing, the server could return a 500 despite having already added the sample to the database first. We now pass on exception since the relational db is the source of truth and opensearch can just be reindexed, ensuring the client correctly receives 201 Created.

vasques1 added 3 commits April 8, 2026 11:47
- Add optional run_barcode field to SampleCreate and SamplePublic models
- Enrich POST /projects/{pid}/samples to create SampleSequencingRun when
  run_barcode is provided, eliminating the separate association call
- Build explicit SamplePublic in route to echo run_barcode in response
- Add robust error handling for malformed barcodes in add_sample_to_project
- Add BulkSampleCreateRequest/Response models and bulk route endpoint
…and tests

- Add bulk_create_samples() in api/samples/services.py with:
  - Pre-validation: duplicate sample_ids, invalid barcodes, duplicate attr keys
  - Single-transaction creation loop with idempotent semantics
  - Resolve-or-create samples + optional SampleSequencingRun associations
  - Post-commit best-effort OpenSearch indexing
  - Robust error handling for malformed barcodes
- Add comprehensive test suite (22 tests) in tests/api/test_bulk_samples.py:
  - Single-sample run_barcode: happy path, backward compat, invalid barcode
  - Bulk: basic, with run, attributes, mixed, idempotency, re-demux
  - Validation: empty list, duplicates, bad barcode, extra fields, nonexistent project
Wrap the post-commit add_object_to_index call in add_sample_to_project()
with try/except, matching the bulk endpoint's behaviour. Since the DB is
the source of truth and /reindex can resync, an OpenSearch outage should
not cause a 500 after a successful database commit.
@accumb3ns accumb3ns requested a review from golharam April 8, 2026 16:20
Add sections to SAMPLE_RUN_ASSOCIATIONS.md covering:
- POST /projects/{pid}/samples with optional run_barcode enrichment
- POST /projects/{pid}/samples/bulk with atomic batch semantics,
  idempotency, and pre-validation error table
- Updated source files table with new service/test files
@golharam golharam merged commit 5ca191e into main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants