[Python] Can't define variable in pydantic init function

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I want to define a BaseDomain model that inherits from pydantic BaseModel like below

    class BaseDomain(BaseModel):

    def __init__(self, **kwargs):
    self.__exceptions = []

    def add_error(self, exception: GeneralException):
    self.__exceptions.append(exception)



    but I get this error when I use Product model that inherits from BaseDomain

    ValueError: "Product" object has no field "_BaseDomain__exceptions"

    Continue reading...

Compartilhe esta Página