Skip to content

Commit

Permalink
Raise error if settings from file is not a dict
Browse files Browse the repository at this point in the history
We verify the loaded settings from files is dict, otherwise we raise a
SettingsError. With that change, we make Pydantic fails a bit faster.
  • Loading branch information
Julian Vanden Broeck committed Nov 7, 2024
1 parent 0225b19 commit c6e6fb9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,10 @@ def _read_files(self, files: PathType | None) -> dict[str, Any]:
settings = self._read_file(file_path)
except ValueError as e:
raise SettingsError(f'Failed to parse settings from {file_path}, {e}')
if not isinstance(settings, dict):
raise SettingsError(
f'Failed to parse settings from {file_path}, expecting an object (valid dictionnary)'
)
vars.update(settings)
return vars

Expand Down

0 comments on commit c6e6fb9

Please sign in to comment.