Skip to content

Add Metadata Selector API with POST /investigations endpoint - #686

Draft
joshdimanteto wants to merge 8 commits into
developfrom
feature/metadata-selector
Draft

joshdimanteto wants to merge 8 commits into
developfrom
feature/metadata-selector

Conversation

@joshdimanteto

@joshdimanteto joshdimanteto commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Testing Instructions

  • Review code
  • Check GitHub Actions build
  • If icatdb Generator Script Consistency Test CI job fails, is this because of a deliberate change made to the script to change generated data (which isn't actually a problem) or is here an underlying issue with the changes made?
  • Review changes to test coverage
  • Does this change mean a new patch, minor or major version should be made? If so, does one of the commit messages feature fix:, feat: or BREAKING CHANGE: so a release is automatically made via GitHub Actions upon merge?
  • Play around with this example body on the open api docs
   {
   "id": 1,
   "name": "string",
   "visit_id": "string",
   "title": "string",
   "summary": "string",
   "data_collection_investigations": [{"id": 1}],
   "samples": [{"id": 1}],
   "investigation_groups": [{"id": 1}],
   "investigation_instruments": [{"id": 1}],
   "study_investigations": [{"id": 1}],
   "shifts": [{"id": 1}],
   "funding_references": [{"id": 1}],
   "investigation_users": [{"id": 1}],
   "keywords": [
       {"id": 22},
       {"id": 85},
       {"id": 117},
       {"id": 242},
       {"id": 263},
       {"id": 362},
       {"id": 469},
       {"id": 480},
       {"id": 495}
   ],
   "datasets": [{"id": 1}, {"id": 61}],
   "publications": [{"id": 59}, {"id": 118}, {"id": 177}],
   "investigation_facility_cycles": [],
   "parameters": [{"id": 1}]
} 

- Add metadata_selector_api as its own sub-API
- POST /investigations checks that the source Investigation exists and that every supplied related ID belongs to it
- Omitted relationship lists default to every related record; supplied lists, even empty ones, are used as given
- Fails fast on the first list with IDs not found in the Investigation
- Update config.yaml.example, .env.example and test_config_data
- Add unit and integration tests
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.34025% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.87%. Comparing base (d5e38cf) to head (ea2b985).
⚠️ Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
datagateway_api/main.py 85.71% 3 Missing ⚠️
...tagateway_api/metadata_selector_api/ingest_file.py 99.21% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #686      +/-   ##
===========================================
- Coverage   100.00%   99.87%   -0.13%     
===========================================
  Files           54       59       +5     
  Lines         2897     3140     +243     
===========================================
+ Hits          2897     3136     +239     
- Misses           0        4       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Return every column of the Investigation and each selected related record, nested following the ICAT schema:
  owned relationships to every level (e.g. datasets > datafiles > parameters) and the shared records they refer to
  (users, parameter types with permissible string values, instruments, facilities etc.)
- Use the models generated from the ICAT schema (build_datagateway_api_model) as the response model, replacing the
  hand-written response models
- Never include back-references to a parent or the collections of shared records, so the nesting cannot recurse
- Nest each selected Dataset's Datafiles under it and add the Samples used by the selected Datasets
- Split ID lists into batches and fetch results in pages, halving a page that exceeds ICAT's maxEntities
- Keep failing fast: all supplied IDs are checked before any full records are fetched
- Update integration tests for the full document, paging and batching
- Add POST /metadata-selector/investigations/xml, which takes the same request as POST /investigations and returns
  the new Investigation in python-icat's XML dump format, loadable with icatingest
- Write every record once, referring to related records by unique key, so the file is self-contained: shared records
  first, then the Investigation, its Samples, Datasets and Datafiles
- Fetch records as the requesting user, batching ID lists and fetching in chunks to stay within ICAT's limits
- Move the request checks into check_metadata_selection, shared by both endpoints
- Add integration tests, including reading the file back with python-icat's dump file reader
- Add docs/metadata_selector_ingest_formats.md comparing the JSON and XML formats, with the results of ingesting into
  a new ICAT and the fix for loading into an ICAT that already has some shared records
@joshdimanteto joshdimanteto changed the title feature: Add Metadata Selector API with POST /investigations endpoint Add Metadata Selector API with POST /investigations endpoint (XML and JSON) Dec 1, 2026
@joshdimanteto joshdimanteto changed the title Add Metadata Selector API with POST /investigations endpoint (XML and JSON) Add Metadata Selector API with POST /investigations endpoint Dec 2, 2026
@joshdimanteto
joshdimanteto force-pushed the feature/metadata-selector branch from 8a3f7a1 to 16dc9f2 Compare December 2, 2026 11:29
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.

1 participant