Skip to content

when extra is allowed, representation is break #3234

@losnuyh

Description

@losnuyh

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

python -c "import pydantic.utils; print(pydantic.utils.version_info())"
             pydantic version: 1.8.2
            pydantic compiled: False
                 install path: /Users/Sol/Project/pydantic/pydantic
               python version: 3.9.5 (default, Jun 23 2021, 22:47:04)  [Clang 11.0.3 (clang-1103.0.32.62)]
                     platform: macOS-10.15.6-x86_64-i386-64bit
     optional deps. installed: ['devtools', 'dotenv', 'email-validator', 'typing-extensions']
from pydantic import BaseModel
from pydantic import Extra



class Foo(BaseModel):
    a: int

    class Config:
        extra = Extra.allow


f = Foo(a=1, b=2)
breakpoint()
print(f) # << raise error. not only 'print', also str(Model), breakpoint().. etc

because

field b that allowed is not in Model.fields

in main.BaseModel

class BaseModel(Representation, metaclass=ModelMetaclass):

    ...

    def __repr_args__(self) -> 'ReprArgs':
        return [(k, v) for k, v in self.__dict__.items() if self.__fields__[k].field_info.repr] # KeyError

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions