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

Fix nested model problem when case_sensitive=False #34

Merged
merged 4 commits into from
Apr 27, 2023

Conversation

hramezani
Copy link
Member

@hramezani hramezani commented Apr 27, 2023

Fixes #9

@hramezani hramezani requested a review from samuelcolvin April 27, 2023 11:06
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM.

Comment on lines 181 to 183
if not field.annotation:
values[name] = value
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this is necessary? It looks like where this is called field.annotations is always a BaseModel - also the next line assumes field.annotation.model_fields always exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's here only to make mypy happy

Item "None" of "Optional[Type[Any]]" has no attribute "model_fields"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, please add a comment saying that, and also support the case where field.annotations is not None but is not a BaseModel - e.g. has no .model_fields attribute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@hramezani
Copy link
Member Author

@samuelcolvin I've also added a comment to ignore fields with validation_alias. a test also has been added

@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2023

Codecov Report

Patch coverage: 85.71% and project coverage change: -0.75 ⚠️

Comparison is base (0ac8e81) 96.00% compared to head (c9ecb6d) 95.25%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
- Coverage   96.00%   95.25%   -0.75%     
==========================================
  Files           5        5              
  Lines         275      295      +20     
  Branches       67       74       +7     
==========================================
+ Hits          264      281      +17     
- Misses         10       12       +2     
- Partials        1        2       +1     
Impacted Files Coverage Δ
pydantic_settings/sources.py 95.20% <85.71%> (-0.89%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.


By having the following models:

class SubSubSub(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one comment (doesn't matter much here since I guess we won't add this to the documentation) - if you want code in docsting, please use markdown with code fences so they examples render properly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Done!

@hramezani hramezani enabled auto-merge (squash) April 27, 2023 12:16
@hramezani hramezani merged commit e10b1c9 into pydantic:main Apr 27, 2023
@hramezani hramezani deleted the nested_model_case_sensitive branch April 27, 2023 12:24
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.

The nested BaseSettings raise a validation error when its attribute is uppercase.
3 participants