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

Loading nested settings #4988

Closed
5 of 15 tasks
dalefrancis88 opened this issue Jan 27, 2023 · 6 comments
Closed
5 of 15 tasks

Loading nested settings #4988

dalefrancis88 opened this issue Jan 27, 2023 · 6 comments
Labels
bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable

Comments

@dalefrancis88
Copy link

dalefrancis88 commented Jan 27, 2023

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

I am trying to load in nested settings using pydantic with the latest versions and yet it's still not loading in anything. It's as if it's not reading/seeing any environment variables properly. I pulled the example code from the last post here as well as refrencing the docs and i can get is to load the top level but not the nested values

pydantic/pydantic-settings#43

Been working through this for half the day and cannot for the life of me figure out the issue. I've even done fresh installs

Example Code

import os

from pydantic import BaseModel, BaseSettings

os.environ.setdefault("v0", "A")
os.environ.setdefault("v1", "B")
os.environ.setdefault("sub_model__v2", "C")

class SubModel(BaseModel):
    V2: str


class Settings(BaseSettings):
    v0: str
    V1: str
    sub_model: SubModel | None

    class Config:
        case_sensitive = True
        env_nested_delimiter = "__"

print(Settings().dict())
# {'v0': 'A', 'V1': 'B', 'sub_model': {'V2': 'C'}}

Python, Pydantic & OS Version

pydantic version: 1.10.4
            pydantic compiled: True
                 install path: C:\Users\xxxx\anaconda3\envs\py3109\Lib\site-packages\pydantic
               python version: 3.10.9 | packaged by conda-forge | (main, Jan 11 2023, 15:15:40) [MSC v.1916 64 bit (AMD64)]
                     platform: Windows-10-10.0.22000-SP0
     optional deps. installed: ['dotenv', 'typing-extensions']

Affected Components

@dalefrancis88 dalefrancis88 added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Jan 27, 2023
@samuelcolvin
Copy link
Member

Is this a duplicate of pydantic/pydantic-settings#27?

@dalefrancis88
Copy link
Author

Possible, looks like it might just be the sub settings are not being loaded at all?

@samuelcolvin
Copy link
Member

They definitely are as per pydantic/pydantic-settings#27.

@dalefrancis88
Copy link
Author

@samuelcolvin So what is the resolution here? wait for the fix from #4498 or use a pre-release version?

@samuelcolvin
Copy link
Member

I don't think #4498 is related.

Best to use the work around described in pydantic/pydantic-settings#27, e.g. NESTED__SUB_VAR1.

See also #4991 (comment)

@dalefrancis88
Copy link
Author

@samuelcolvin sorry i typed that wrong, it was unintentional

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 unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

No branches or pull requests

2 participants