-
-
Notifications
You must be signed in to change notification settings - Fork 110
Cli subcommand with annotation #579
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,6 +474,21 @@ class AnnotatedComplexSettings(BaseSettings): | |
| ] | ||
|
|
||
|
|
||
| def test_cli_nested_annotated_unions(env): | ||
| class Cat(BaseModel): | ||
| meow: str | ||
|
|
||
| class Dog(BaseModel): | ||
| woof: str | ||
|
|
||
| class Settings(BaseSettings): | ||
| model_config = SettingsConfigDict(env_nested_delimiter='__') | ||
| animals: Annotated[Union[Annotated[Union[Cat, Dog], 'my_nested_annotation'], None], 'my_annotation'] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hramezani I have the top level fix for the CLI in place. However, I discovered that the env parsing does not handle nested annotated unions properly. I've added a test case here to demonstrate the issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a special case. I am sure that there are more cases that fail(we are not aware of them). |
||
|
|
||
| env.set('ANIMALS__MEOW', 'hiss') | ||
| assert Settings().model_dump() == {'animals': {'meow': 'hiss'}} | ||
|
|
||
|
|
||
| def test_set_dict_model(env): | ||
| env.set('bananas', '[1, 2, 3, 3]') | ||
| env.set('CARROTS', '{"a": null, "b": 4}') | ||
|
|
||
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.
@hramezani From what I observed, it appears to be related to incorrectly determining that nested annotated unions are not complex. This change fixed it, but causes other tests fail. I'm not sure if it is the correct fix. Can you take a look?
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.
Sorry @kschwab for the delay.
I am also not sure what the correct fix is here. As the change breaks some existing tests, I would prefer to remove it.
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.
No worries @hramezani. I'm ok with closing this as a won't fix as well.