Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when extra is allowed, representation is break #3234

Closed
3 tasks done
COCOLMAN opened this issue Sep 20, 2021 · 1 comment · Fixed by #3241
Closed
3 tasks done

when extra is allowed, representation is break #3234

COCOLMAN opened this issue Sep 20, 2021 · 1 comment · Fixed by #3241
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@COCOLMAN
Copy link
Contributor

COCOLMAN commented Sep 20, 2021

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
@COCOLMAN COCOLMAN added the bug V1 Bug related to Pydantic V1.X label Sep 20, 2021
@povilasb
Copy link

Triggered this bug as well.
Did a quick git bisect and seems like this commit is the culprit: 362f4a5

samuelcolvin added a commit that referenced this issue Dec 19, 2021
* exclude extra field when represent model

* add test code

* fix W293

* add change md

* Update changes/3234-cocolman.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Update pydantic/main.py

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Update tests/test_main.py

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants