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:
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

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