본문 바로가기
Programing Language/Python

[Python] pydantic.error_wrappers.ValidationError

by pcm9881 2023. 5. 21.

pydantic.error_wrappers.ValidationError: 1 validation error for ...
response -> ...
  none is not an allowed value (type=type_error.none.not_allowed)

 

내용

response_model에 선언되어 있는 pydantic class 필드 값이 None이 허용되게 하지 않았기 때문입니다.

 

해결방안

typingOptional과 함께 None을 허용하게 사용해주면 됩니다.

from typing import Optional
from datetime import datetime
from pydantic import BaseModel

class UserBase(BaseModel):
	...
    deleted_at: Optional[datetime] =  None

 

참조

[pydantic docs]: https://docs.pydantic.dev/latest/usage/types/

 

Field Types - Pydantic

Field Types Where possible pydantic uses standard library types to define fields, thus smoothing the learning curve. For many useful applications, however, no standard library type exists, so pydantic implements many commonly used types. If no existing typ

docs.pydantic.dev

 

728x90

댓글