webrecorder / browsertrix

Browsertrix is the hosted, high-fidelity, browser-based crawling service from Webrecorder designed to make web archiving easier and more accessible for all!
https://browsertrix.com
GNU Affero General Public License v3.0
159 stars 29 forks source link

Fix serialization of datetimes to include Z suffix #1922

Open tw4l opened 1 month ago

tw4l commented 1 month ago

We store datetimes in UTC but they are not returned with a Z suffix from the API, which requires us to manually add it in the frontend.

We should modify serialization to return timezone from the API. See: https://stackoverflow.com/questions/66548586/how-to-change-date-format-in-pydantic

Ideally we could do this globally so we don't need to modify every class with a datetime.

The PR should also update the frontend where a Z is being added manually.

tw4l commented 1 month ago

Pydantic 2 supports lots of custom serialization: https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers. We could likely use the the PlainSerializer to make a custom datetime type that serializes out with the Z suffix.

Since Pydantic 1 doesn't have similarly functionality, this should be considered blocked on upgrading to Pydantic 2. That migration is tracked here: https://github.com/webrecorder/browsertrix/issues/1940