microbiomedata / nmdc-server

Data portal client and server for NMDC.
https://data.microbiomedata.org
Other
9 stars 0 forks source link

Add ability to store Field Notes-related metadata on submissions #1473

Closed pkalita-lbl closed 4 days ago

pkalita-lbl commented 4 days ago

Related to https://github.com/microbiomedata/nmdc-field-notes/issues/150

Summary

We have a use case for the Field Notes app where we want to attach a bit of Field Notes-specific information to a submission and have it shared between all users with access to that submission (i.e. the app's local storage wont cut it). These changes add a field_notes_metadata column to the submission_metadata table. They also update the API to provide this information in GET requests and to accept this information in PATCH requests.

Details

The field_notes_metadata column which is being added here is a JSONB column. I'm sort of intentionally not strongly typing the column any further than Optional[Dict[str, Any]]. My thought is that this column is a black box as far as nmdc-server is concerned (the Field Notes code will, however, make stronger claims about what format it will save to and retrieve from the field). This also should allow us to expand what Field Notes uses field_notes_metadata for in the future without nmdc-server changes.

A bit of an aside, but I got called out by mypy for the JSONB() call in the new migration. I saw that elsewhere in the code standard practice was to just add a type: ignore. I was curious and started poking around, and I found that the sqlalchemy-stubs package is more-or-less unmaintained at this point and doesn't support SQLAlchemy 1.4 (which we use) particularly well (hence the need for type: ignore). The SQLAlchemy 1.4 docs now point you to the sqlalchemy2-stubs package. I was hoping maybe I could just drop that in as a replacement. But I gave it a whirl, and it came up with a lot of typing errors (but not the JSONB one!) So I guess just something to consider in our expansive free time.