question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Config.extra` is messed-up when using multiple inheritance/mixins

See original GitHub issue

Bug

  • 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
samuelcolvincommented, Feb 14, 2019

fixed by #394

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found