Skip to content

fix: preserve last-directory nested secrets precedence for mixed-case names - #969

Open
cpruijsen wants to merge 1 commit into
pydantic:mainfrom
cpruijsen:fix/issue-960
Open

fix: preserve last-directory nested secrets precedence for mixed-case names#969
cpruijsen wants to merge 1 commit into
pydantic:mainfrom
cpruijsen:fix/issue-960

Conversation

@cpruijsen

Copy link
Copy Markdown

Each directory is now passed through parse_env_vars before the merge, so mixed-case names collide on the same key and a later directory overwrites. That is the same order DotEnvSettingsSource already uses for multiple env files. Fixes #960.

When secrets_dir is a list, NestedSecretsSettingsSource is documented as last-directory-wins. Under the default case-insensitive matching, NestedSecretsSettingsSource merged raw filenames first, then lowercased keys. Python dicts keep a key's insertion position when its value is replaced, so directories TOKEN=first, token=second, TOKEN=third produced token=second instead of third.

Parse then dict.update, matching _read_env_files. Alternative was keeping reduce and wrapping parse_env_vars in the generator. Can switch if you would rather keep reduce.

… names

Normalize each secrets_dir before merging so last-directory-wins still holds
when filenames differ only by case.
@macroscopeapp

macroscopeapp Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This changes production secret-resolution behavior and can alter which sensitive credential value is selected when filenames differ by case. Although the implementation is focused and tested, the sensitive-data implications warrant human review.

You can add or adjust custom eligibility rules. Learn more.

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.

Nested secrets directory precedence changes with filename casing

1 participant