votes up 1

Field name "(field_name)" shadows a BaseModel attribute; use a different field name with "alias='(field_name)'".

Exception Class:

Raise code

e_field_name(bases: List[Type['BaseModel']], field_name: str) -> None:
    Ensure that the field's name does not shadow an existing attribute of the model.
    for base in bases:
        if getattr(base, field_name, None):
            raise NameError(
                f'Field name "{field_name}" shadows a BaseModel attribute; '
                f'use a different field name with "alias=\'{field_name}\'".'

def lenient_issubclass(cls: Any, class_or_tuple: Union[Type[Any], Tuple[Type[Any], ...]]) -> bool:
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 2 votes down


from pydantic import BaseModel, Field
class WrongProduct(BaseModel):
  id: int
  schema: str # shadows a BaseModel attribute error

class CorrectProduct(BaseModel):
  id: int
  _schema: str = Field(alias="schema") # No error
Jul 15, 2022 rivashchenko answer

Add a possible fix

Please authorize to post fix