Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSPT-208 Serialise application date submitted in a guaranteed format #126

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

sfount
Copy link
Contributor

@sfount sfount commented Jan 7, 2025

date_submitted is stored both in the application table and in the JSON representation of an application used by the assess tool.

Marshmallow will serialise the properties from the application model depending on if there is timezone information included or not. Previously the application store was first "submitting" an application (updating the status and setting the date_submitted property) in one database transaction and then separately fetching the application and putting in on a queue to be processed by assess.

When we changed this behaviour to update the application and write to the assessment table in one transaction we don't fetch a new application from the database.

When the date_submitted property is set directly in the code we have been including timezone.utc on the datetime property. When the application is fetched from the database it does not include (or store) the timezone information - I'm assuming everything by default is in UTC.

This means that we changed to serialising the JSON with timezone information (+00.00) which caused issues when the assessment code tried to serialise it.

This is one method of dealing with that and explicitly instructs marshmallow to serialise the JSON (then stored in the jsonb_blob property of assessments) using the format that has been used so far.

samuelhwilliams
samuelhwilliams previously approved these changes Jan 8, 2025
Copy link
Contributor

@samuelhwilliams samuelhwilliams left a comment

Choose a reason for hiding this comment

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

I think this is a sensible enough approach for the short-term 👍

No tests, nothing, all good 👀

Are we gonna go through and clean up the DB(s) too?

@sfount
Copy link
Contributor Author

sfount commented Jan 8, 2025

I'm a bit hesitant to test that marshmallow knows how to serialise JSON but you're right that this addresses a change that caused down stream issues - I've added an assertion on the existing submit tests to avoid that changing without us catching it cf5c9d7

@sfount sfount force-pushed the FSPT-208-patch-date-submitted branch from 5cd4518 to cf5c9d7 Compare January 8, 2025 10:39
@sfount sfount enabled auto-merge January 8, 2025 10:43
@sfount sfount force-pushed the FSPT-208-patch-date-submitted branch from cf5c9d7 to 5442be2 Compare January 8, 2025 13:13
Copy link
Contributor

@samuelhwilliams samuelhwilliams left a comment

Choose a reason for hiding this comment

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

✅ also - SQL update as script as discussed

sfount added 2 commits January 8, 2025 16:50
`date_submitted` is stored both in the application table and in the JSON
representation of an application used by the assess tool.

Marshmallow will serialise the properties from the application model
depending on if there is timezone information included or not.
Previously the application store was first "submitting" an application
(updating the status and setting the `date_submitted` property) in
one database transaction and then separately fetching the application
and putting in on a queue to be processed by assess.

When we changed this behaviour to update the application and write to
the assessment table in one transaction we don't fetch a new application
from the database.

When the `date_submitted` property is set directly in the code we have
been including `timezone.utc` on the `datetime` property. When the
application is fetched from the database it does not include (or store)
the timezone information - I'm assuming everything by default is in UTC.

This means that we changed to serialising the JSON with timezone
information (`+00.00`) which caused issues when the assessment code
tried to serialise it.

This is one method of dealing with that and explicitly instructs
marshmallow to serialise the JSON (then stored in the `jsonb_blob`
property of assessments) using the format that has been used so far.
There are a lot of steps between configuring that date format we would
expect to see and JSON being set in a separate (assess) table.

Add a regression test against this changing formats.
@sfount sfount force-pushed the FSPT-208-patch-date-submitted branch from 5442be2 to 7f908b1 Compare January 8, 2025 16:50
Copy link

sonarqubecloud bot commented Jan 8, 2025

@sfount sfount merged commit 0e44fb3 into main Jan 8, 2025
9 checks passed
@sfount sfount deleted the FSPT-208-patch-date-submitted branch January 8, 2025 16:55
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