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

API does not return milliseconds in datetimes even when present in underlying data #606

Closed
ml-evs opened this issue Nov 19, 2020 · 2 comments
Labels
bug Something isn't working priority/medium Issue or PR with a consensus of medium priority server Issues pertaining to the example server implementation

Comments

@ml-evs
Copy link
Member

ml-evs commented Nov 19, 2020

Just ran into this while hacking on #595.

Some combination of FastAPI/pydantic is ripping out the milliseconds in responses containing date-times. This causes the validator to get upset when it tests that a query like last_modified>2018-06-08T04:13:37Z doesn't return the original object it scraped the time from, but in reality the object has an amount of fractional seconds added onto it in the database, so it is correctly included in the "exclusive" query.

@ml-evs ml-evs added bug Something isn't working priority/medium Issue or PR with a consensus of medium priority server Issues pertaining to the example server implementation labels Nov 19, 2020
@ml-evs ml-evs changed the title API does not return milliseconds in datetimes even when presnt in underlying data API does not return milliseconds in datetimes even when present in underlying data Nov 20, 2020
@ml-evs
Copy link
Member Author

ml-evs commented Nov 23, 2020

This is very frustrating, can't replicate with a MWE.

The milliseconds in the timestamp persist all the way to the response model that gets returned, so it must be the JSON encoder of FastAPI/pydantic that's doing it, but every MWE I try ends up with milliseconds being returned just fine 👿

Any ideas @shyamd? Don't know if you run into this? Think this is quite important to fix.

@ml-evs
Copy link
Member Author

ml-evs commented Nov 23, 2020

The answer: RFC3339 does not allow milliseconds so the response models were patched to enforce it:

class Config:
json_encoders = {
datetime: lambda v: v.astimezone(timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%SZ"
),
}

Now need to decide whether to adjust other models/validator accordingly.

@ml-evs ml-evs closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority/medium Issue or PR with a consensus of medium priority server Issues pertaining to the example server implementation
Projects
None yet
Development

No branches or pull requests

1 participant