`Config.extra` is messed-up when using multiple inheritance/mixins
See original GitHub issueBug
- OS: Ubuntu 18.04
- Python version: 3.7.1
- Pydantic version: 0.19
extra
Config option does not seem to propagate correctly when using multiple inheritance/mix-ins.
Other options seem to work OK.
import pydantic
class Base(pydantic.BaseModel):
field: str
class Config:
allow_mutation = False
use_enum_values = True
extra = pydantic.Extra.forbid
class Mixin(pydantic.BaseModel):
another_field: int = 0
class SubClass(Mixin, Base):
yet_another_field: float = 0.1
assert pydantic.BaseModel.__config__.allow_mutation is True
assert pydantic.BaseModel.__config__.use_enum_values is False
assert pydantic.BaseModel.__config__.extra == pydantic.Extra.ignore
assert Base.__config__.allow_mutation is False
assert Base.__config__.use_enum_values is True
assert Base.__config__.extra == pydantic.Extra.forbid
assert SubClass.__config__.allow_mutation is False
assert SubClass.__config__.use_enum_values is True
assert SubClass.__config__.extra == pydantic.Extra.forbid # FAILS HERE; RESET TO `ignore`
Potentially caused by the way legacy allow_extra
/ ignore_extra
are supported.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
`Config.extra` is messed-up when using multiple inheritance ...
extra Config option does not seem to propagate correctly when using multiple inheritance/mix-ins. Other options seem to work OK. import pydantic ...
Read more >Fake It 'til You Make It - Emulating Multiple Inheritance in ...
Even though SystemVerilog doesn't provide multiple inheritance, using the mixin pattern we can emulate it by using only single inheritance.
Read more >Changelog - pydantic
Now that Config.extra is supported, dataclass ignores by default extra arguments (like BaseModel ). Fix PEP487 __set_name__ protocol in ...
Read more >pydantic [python-library] - Occam :: Details
Data validation and settings management using Python type hinting. ... Fix extra behaviour for multiple inheritance/mix-ins, #394 by @YaraslauZhylko ...
Read more >Problems With Abc/Interfaces Using Pydantic + Mixins Pattern
Pydantic is a library for data validation and settings management based on ... 0.19 Config.extra is messedup when using multiple inheritance/mixins #392.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fixed by #394
@samuelcolvin PR’s ready: https://github.com/samuelcolvin/pydantic/pull/394