Skip to content

Conversation

@kschwab
Copy link
Contributor

@kschwab kschwab commented Apr 7, 2025

Fixes #573


class Settings(BaseSettings):
model_config = SettingsConfigDict(env_nested_delimiter='__')
animals: Annotated[Union[Annotated[Union[Cat, Dog], 'my_nested_annotation'], None], 'my_annotation']
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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).
I would prefer keeping the code base simple and preventing breaking change instead of supporting all complex scenarios.


# Check if annotation is of the form Union[type, ...].
if typing_objects.is_union(origin):
return _union_is_complex(annotation, metadata)
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@kschwab
Copy link
Contributor Author

kschwab commented Apr 12, 2025

Closing as won't fix due to maintenance and complexity concerns.

@kschwab kschwab closed this Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discriminated Unions and Nested CLI Subcommands

2 participants