New to Pydantic and fail to understand why this is failing when the json has the key.
from pydantic import BaseModel
class Event(BaseModel):
id: str
external_data = """
{
"id": "abcdef",
"status": "confirmed"
}
"""
event = Event().model_validate_json(external_data)
print(event)
pydantic version: v2.7.4, pydantic-core version: v2.18.4
Traceback (most recent call last):
File "", line 16, in
File "/lib/python3.11/site-packages/pydantic/main.py", line 176, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Event
id
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.7/v/missing`
It seems to only work if I set ‘id: str’ -> ‘id: str=None’