-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Feat/support complex list definition on env vars [Closes #376] #377
base: main
Are you sure you want to change the base?
Conversation
try: | ||
# check if key is an integer. If so, it's an index. we fake a field info with the list type | ||
# so future calls can continue to traverse the model and set proper types for leaf nodes | ||
int(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need a test case with non int index
pydantic_settings/sources.py
Outdated
result, values = [], result | ||
for i in (str(i) for i in range(len(values))): | ||
if i not in values: | ||
raise ValueError(f'Expected entry with index {i} for {field_name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a test case for this line as well
Thanks @inean for this PR. please:
|
@inean is it going to support simple cases like: class Config(BaseSettings):
top: List[str]
config = Config() by |
|
@hramezani Just one question: given this code... class TopModel(BaseModel):
v1: str | None = None
v2: int
class Settings(BaseSettings):
top: List[List[TopModel]]
...
env.set(TOP='[[{'v2': 'xx'}]]')
env.set(TOP__0__0__v2 = '1')
env.set(TOP__1__0__v2 = '2')
env.set(TOP__3__0__v2='3')
cfg = Settings() Should |
@inean Thanks for the update and sorry for being late. After discussing with the team about supporting this syntax, we decided not to support it because:
|
Proposal of implementation. It works but no sanity check on indexes are done 😅