Replies: 1 comment 6 replies
-
|
The major change from FastAPI < 100 to FastAPI 100.0 is that Pydantic was upgraded to 2.0. Recreating something like your sample below from fastapi import FastAPI
from fastapi.testclient import TestClient
from datetime import datetime, date
import uvicorn
import pytz
import pytest
app = FastAPI()
@app.get("/")
async def root():
test_date = datetime.now()
test_date_tz = (datetime.now().replace(tzinfo=pytz.UTC)).isoformat()
return {
"date": test_date,
"date_tz": test_date_tz
}
client = TestClient(app)
def test_date():
response = client.get("/")
print( response.json())
test_date = datetime.strptime(response.json()["date_tz"], "%Y-%m-%dT%H:%M:%S.%f+00:00").date()
print(test_date){'date': '2023-07-16T12:04:18.439371', 'date_tz': '2023-07-16T12:04:18.439375+00:00'}I do not get a Z in my response. Perhaps it is related to the types that are not included in your sample code but we probably need a more complete piece of code to see what might be happening. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
+00:00" is a valid ISO 8601 timezone designation for UTC. But this seems to have changed to Z. Is there a way to change this?
In fastapi==0.95.0 we created our ISO date like this and returned it as json:
The unit test was expecting a dateformat like this:
2023-07-16T06:26:30.769459+00:00But now with fastapi==0.100.0 the format has changed:
2023-07-16T06:26:30.769459ZIs there a way to change this back to +00:00?
Many Thanks
Operating System
Linux
Operating System Details
MacOS and Linux
FastAPI Version
0.100.0
Python Version
3.11.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions