Pydantic: Settings inheritance with ENV prefix does not work

Created on 9 Dec 2019  路  5Comments  路  Source: samuelcolvin/pydantic

Bug

  • OS: ubuntu 18.04
  • Python version import sys; print(sys.version): 3.7.5 (default, Nov 7 2019, 10:50:52)
  • Pydantic version import pydantic; print(pydantic.VERSION): 1.0b1 or 1.2, but works fine with 0.32
import os
from pydantic import BaseSettings


class MyBaseSettings(BaseSettings):
    var: int = 10


class MySubSettings(MyBaseSettings):
    class Config:
        env_prefix = 'PREFIX_'


os.environ['PREFIX_VAR'] = '2'
k = MySubSettings()
print(k.var)  # 10, but should be 2

We expect that k.var will be equal to 2, but it has default value 10.
It's reproduced since 1.0b1.

bug

Most helpful comment

I'm looking into this, but I'm afraid the solution isn't trivial.

Weird that this got 11 :+1: and 2 :eyes: in 2 hours. Any idea why this happened?

All 5 comments

I'm looking into this, but I'm afraid the solution isn't trivial.

Weird that this got 11 :+1: and 2 :eyes: in 2 hours. Any idea why this happened?

Yep, we are team.

Thanks for quick support! Hope fix won't be difficult.

That's what exactly happens when you upgrade your project with Pydantic from 0.32 to 1.2 directly... Thank you for support, @samuelcolvin !

See #1093, should be fixed there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gaunt picture Gaunt  路  19Comments

rrbarbosa picture rrbarbosa  路  35Comments

jasonkuhrt picture jasonkuhrt  路  19Comments

Yolley picture Yolley  路  18Comments

koxudaxi picture koxudaxi  路  25Comments