Skip to content

NO TICKET: removed admin and old schemas, added observation/water-chemistry#66

Merged
jirhiker merged 17 commits into
pre-productionfrom
jir-sample-observation
Aug 8, 2025
Merged

NO TICKET: removed admin and old schemas, added observation/water-chemistry#66
jirhiker merged 17 commits into
pre-productionfrom
jir-sample-observation

Conversation

@jirhiker

@jirhiker jirhiker commented Aug 7, 2025

Copy link
Copy Markdown
Member

Why

This PR addresses the following problem / context:

  • The DataManager will serve as the admin UI
  • There was some old code that was cluttering the code base
  • Needed a POST observation/water-chemistry endpoint for use with the Water Chemistry CSV Import app

How

Implementation summary - the following was changed / added / removed:

  • deleted schemas, admin
  • added observation/water-chemistry to observation router

Notes

Any special considerations, workarounds, or follow-up work to note?

  • Use bullet points here

jirhiker and others added 2 commits August 7, 2025 15:47
@jirhiker jirhiker changed the title refactor: removed admin and old schemas feat: added observation/water-chemistry NO TICKET: removed admin and old schemas, added observation/water-chemistry Aug 8, 2025
@jirhiker jirhiker marked this pull request as ready for review August 8, 2025 05:13
Comment thread api/observation.py


@router.post("/water-chemistry", status_code=HTTP_201_CREATED)
def add_water_chemistry_observation(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to specify a specific type of observation vs adding a general observation? I think the sample_matrix field in the Sample table would indirectly identify the type of observation (groundwater, surface water, soil, etc.)

@jirhiker jirhiker Aug 8, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By limiting to a type of observation, we can perform better data validations, i.e, if all the necessary fields are provided. This would not be as easy or explicit with a general add_observation endpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is something that's necessary at the validation level? Additional fields are not needed in the sample or observation tables, correct?

@jacob-a-brown jacob-a-brown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's really only one schemas directory now. Should the original schemas directory be removed and schemas_v2 be renamed schemas?

Comment thread db/observation.py
Comment thread tests/test_observation.py
Comment on lines +38 to +48
if "field_sample_id" in data:
field_sample_id = data.pop("field_sample_id")
data.pop(
"sample_id", None
) # Ensure sample_id is not set if field_sample_id is used

sql = select(Sample).where(Sample.field_sample_id == field_sample_id)
sample = session.scalar(sql)
if not sample:
raise ValueError(f"Sample with id {field_sample_id} does not exist")
data["sample"] = sample

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this if block can be removed because

  • The observation model and schema don't have a field_sample_id field (this may be an artifact from a previous iteration of the schema?)
  • sample_id is also a non-nullable field with a foreign key constraint, so it should be in the payload (not popped).
    • If the corresponding sample does not exist the database will raise an error and that can be handled at the endpoint (raise a 409 error with an appropriate error message).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary for how the frontend works to upload the csv.

The way the frontend current works, when adding an Observation, it needs to refer to the Sample via the field_sample_id not the Sample.id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that be cause Sample.id is not defined until Sample has been created? If that's the case, could you use the sample_id from the POST /sample response on the frontend? Or, would that not be feasible given how the frontend is setup.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is that be cause Sample.id is not defined until Sample has been created?" correct

Thats probably the correct way to do it eventually, e.g. using the sample_id from POST response.

It wasn't feasible with the current structure, but I have some ideas on how to better implement this in the future and we can remove this if block

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! We can make a note of this and then when the new implementation is done on the frontend this if block can be removed. If a ticket is made for that implementation this could be a subtask. We can also add a # REFACTOR TODO note here as well.

@ksmuczynski ksmuczynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Left a few comments questioning the need to ad a specific type of observation as opposed to a general observation. Open to discussion.

@jacob-a-brown jacob-a-brown self-requested a review August 8, 2025 16:48

@jacob-a-brown jacob-a-brown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments

@jirhiker jirhiker requested a review from jacob-a-brown August 8, 2025 20:40
@codecov-commenter

codecov-commenter commented Aug 8, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.52632% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
services/observation_helper.py 22.22% 7 Missing ⚠️
db/lexicon.py 50.00% 1 Missing ⚠️
schemas/observation.py 90.90% 1 Missing ⚠️
Files with missing lines Coverage Δ
api/asset.py 81.69% <100.00%> (ø)
api/author.py 100.00% <100.00%> (ø)
api/contact.py 94.11% <100.00%> (ø)
api/geochronology.py 86.66% <100.00%> (ø)
api/geospatial.py 100.00% <100.00%> (ø)
api/geothermal.py 100.00% <100.00%> (ø)
api/group.py 96.87% <100.00%> (ø)
api/lexicon.py 96.36% <100.00%> (ø)
api/location.py 74.07% <100.00%> (ø)
api/observation.py 97.22% <100.00%> (ø)
... and 28 more

@jacob-a-brown jacob-a-brown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted down the future removal of the if field_sample_id in data in my backlog notes too

@jirhiker jirhiker merged commit 279413b into pre-production Aug 8, 2025
3 checks passed
@jirhiker jirhiker deleted the jir-sample-observation branch August 29, 2025 14:40
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.

4 participants