Skip to content

Commit c6e6fb9

Browse files
author
Julian Vanden Broeck
committed
Raise error if settings from file is not a dict
We verify the loaded settings from files is dict, otherwise we raise a SettingsError. With that change, we make Pydantic fails a bit faster.
1 parent 0225b19 commit c6e6fb9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pydantic_settings/sources.py

+4
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,10 @@ def _read_files(self, files: PathType | None) -> dict[str, Any]:
19211921
settings = self._read_file(file_path)
19221922
except ValueError as e:
19231923
raise SettingsError(f'Failed to parse settings from {file_path}, {e}')
1924+
if not isinstance(settings, dict):
1925+
raise SettingsError(
1926+
f'Failed to parse settings from {file_path}, expecting an object (valid dictionnary)'
1927+
)
19241928
vars.update(settings)
19251929
return vars
19261930

0 commit comments

Comments
 (0)