Skip to content

NO TICKET: fix sample response & eager load contact attributes#146

Merged
jirhiker merged 5 commits into
stagingfrom
jab-sample-fix
Sep 25, 2025
Merged

NO TICKET: fix sample response & eager load contact attributes#146
jirhiker merged 5 commits into
stagingfrom
jab-sample-fix

Conversation

@jacob-a-brown
Copy link
Copy Markdown
Contributor

@jacob-a-brown jacob-a-brown commented Sep 25, 2025

Why

This PR addresses the following problem / context:

  • the staging database is not yet up-to-date with FieldEvent, FieldEventContact, and FieldActivity, so the fields field_event_id and field_event_contact_id evaluate to None in staging though they are not nullable
  • lazily-loading related tables to contact (email, phone, address, and thing) causes performance issues

How

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

  • commented out field_event_id and field_event_contact_id from the sample response.
  • used joinedload to eagerly load tables related to contact

Notes

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

  • field_event_id and field_event_contact_id probably don't need to be added back because the related tables (and their responses) are returned with the sample response
  • add thing_id query param to /sample
  • no Field... tables are populated in staging (yet). Will this break the responses for contact, field_event, field_actvity, and thing in the SampleResponse?

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
api/contact.py 100.00% <100.00%> (ø)
api/sample.py 100.00% <100.00%> (ø)
schemas/sample.py 98.30% <ø> (ø)
services/contact_helper.py 100.00% <100.00%> (ø)
services/sample_helper.py 100.00% <100.00%> (ø)
tests/test_contact.py 100.00% <100.00%> (ø)
tests/test_sample.py 100.00% <100.00%> (ø)

@jacob-a-brown
Copy link
Copy Markdown
Contributor Author

jacob-a-brown commented Sep 25, 2025

Both sample fixtures are associated with the same thing, so the thing_id query parameter returns both samples. This is the behavior we want (get samples related to a thing). Should I, however, associate one of the samples (and thereby its parent FieldActivity and FieldEvent) to a different thing to ensure that we are only returning the one we want?

@jirhiker
Copy link
Copy Markdown
Member

I think 3 sample fixtures is probably best, so that you are fully testing the functionality

@jirhiker jirhiker merged commit 20b6e80 into staging Sep 25, 2025
3 checks passed
@TylerAdamMartinez TylerAdamMartinez deleted the jab-sample-fix branch February 5, 2026 18:06
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.

3 participants