Skip to content

Fix Config.from_file silent error handling to include ENOTDIR - #5955

Closed
r266-tech wants to merge 1 commit into
pallets:mainfrom
r266-tech:fix-from-file-enotdir
Closed

r266-tech wants to merge 1 commit into
pallets:mainfrom
r266-tech:fix-from-file-enotdir

Conversation

@r266-tech

Copy link
Copy Markdown

Description

Config.from_file() is missing errno.ENOTDIR in its silent error handling, while Config.from_pyfile() correctly includes it.

When a component of the config file path is a regular file rather than a directory (e.g., trying to load file/config.json where file is a regular file), from_file(silent=True) raises an OSError instead of silently returning False.

This inconsistency was originally reported in #5912.

Changes

  • src/flask/config.py: Added errno.ENOTDIR to the error check in from_file(), matching the existing behavior of from_pyfile() (line 211).
  • tests/test_config.py: Added test_config_from_file_not_a_directory to verify the fix.

Before

# from_pyfile (line 211) - correct
if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):

# from_file (line 296) - missing ENOTDIR
if silent and e.errno in (errno.ENOENT, errno.EISDIR):

After

Both methods now handle the same errno values consistently.

Config.from_file() was missing errno.ENOTDIR in its silent error
handling, while Config.from_pyfile() correctly includes it.

When a component of the config file path is a regular file rather
than a directory (e.g., trying to load 'file/config.json' where
'file' is a regular file), from_file(silent=True) would raise an
OSError instead of silently returning False.

This adds ENOTDIR to match from_pyfile's behavior and adds a test
to verify the fix.

Fixes #5912
@davidism davidism closed this Mar 22, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants