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

"extra fields not permitted" error when using Extra.forbid on dataclass property that's a dict or list of another dataclass #4343

Closed
6 of 16 tasks
DetachHead opened this issue Aug 8, 2022 · 5 comments · Fixed by #4354
Assignees
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Aug 8, 2022

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

when instanciating a dataclass where a property is a list or dict of another dataclass, it causes this error:

extra fields not permitted (type=value_error.extra)

Example Code

from pydantic import Extra
from pydantic.dataclasses import dataclass


class ExtraPropertiesForbidden:
    extra = Extra.forbid


@dataclass(config=ExtraPropertiesForbidden)
class Bar:
    ...


@dataclass(config=ExtraPropertiesForbidden)
class Foo:
    a: list[Bar]


a = Foo(a=[Bar()])  # error: extra fields not permitted (type=value_error.extra)

Python, Pydantic & OS Version

this issue seems to have been introduced after the 1.9.1 release. this occurred after installing the latest commit from master:

pip uninstall pydantic
pip install git+https://github.com/samuelcolvin/pydantic.git@a69136d2096e327ed48954a298c775dceb1551d1
pydantic version: 1.9.0
            pydantic compiled: False
                 install path: C:\Users\chungus\AppData\Local\pypoetry\Cache\virtualenvs\project-e01-Hfn1-py3.10\Lib\site-packages\pydantic
               python version: 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
                     platform: Windows-10-10.0.19042-SP0
     optional deps. installed: ['typing-extensions']

Affected Components

@DetachHead DetachHead added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Aug 8, 2022
@samuelcolvin samuelcolvin removed the unconfirmed Bug not yet confirmed as valid/applicable label Aug 8, 2022
@samuelcolvin
Copy link
Member

Very good catch, thank you @DetachHead.

@samuelcolvin samuelcolvin mentioned this issue Aug 8, 2022
14 tasks
@DetachHead DetachHead changed the title "extra fields not permitted" error when using Extra.forbid on dataclass property that's a dict or list orf another dataclass "extra fields not permitted" error when using Extra.forbid on dataclass property that's a dict or list of another dataclass Aug 8, 2022
@samuelcolvin
Copy link
Member

@PrettyWood would be amazing if you could take a look at this 🙏.

@PrettyWood
Copy link
Member

Great catch! I'll check tonight

@DetachHead
Copy link
Contributor Author

i've already fixed it in #4354 if you wanna take a look

@samuelcolvin
Copy link
Member

🙈 sorry I missed that, will look soon.

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
3 participants