Unexpected Null Values When Accessing JSON Properties in FastAPI with Pydantic v1.8
Hey everyone, I'm running into an issue that's driving me crazy. I'm stuck on something that should probably be simple. I've been banging my head against this for hours. I've looked through the documentation and I'm still confused about Quick question that's been bugging me - I am currently using FastAPI (version 0.68.1) along with Pydantic (version 1.8) to build a RESTful API that processes user data... I've defined a Pydantic model to validate incoming JSON data, but I'm running into an scenario where certain properties are returning null values even though they are present in the JSON payload. Here's a snippet of my model and the endpoint: ```python from fastapi import FastAPI from pydantic import BaseModel, Field class User(BaseModel): id: int name: str email: str = Field(..., regex="^\S+@\S+\.\S+$") app = FastAPI() @app.post("/users/") async def create_user(user: User): return user ``` When I send a POST request with the following JSON: ```json { "id": 1, "name": "John Doe", "email": "johndoe@example.com" } ``` I get a proper response. However, when I include an additional field, like this: ```json { "id": 2, "name": "Jane Doe", "email": "janedoe@example.com", "age": 30 } ``` I can see that `age` is ignored, but Iām also confused because I'm not seeing any validation errors, and the properties in the returned object appear correctly; however, they are null when I try to access them in other parts of my application. This leads me to believe that the additional property might be causing an scenario. I have tried using the `Config` class in my Pydantic model to allow for extra fields. ```python class User(BaseModel): id: int name: str email: str = Field(..., regex="^\S+@\S+\.\S+$") class Config: extra = "forbid" ``` I've also tested using `extra = 'allow'` to see if it changes anything, but I still get those null values when trying to access the user object properties later in the application flow. Can anyone help clarify why this is happening and how I can ensure that the properties are correctly populated? For context: I'm using Python on Windows. Is there a better approach? Thanks, I really appreciate it! For context: I'm using Python on Debian. Thanks for any help you can provide! Any help would be greatly appreciated!