Field name "(field_name)" shadows a BaseModel attribute; use a different field name with "alias='(field_name)'".
Package:
pydantic
7315
Exception Class:
NameError
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:
try:
retu
Links to the raise (1)
https://github.com/samuelcolvin/pydantic/blob/45db4ad3aa558879824a91dd3b011d0449eb2977/pydantic/utils.py#L145Ways to fix
SOLUTION:
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
Add a possible fix
Please authorize to post fix