Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/flask/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def from_file(
with open(filename, "r" if text else "rb") as f:
obj = load(f)
except OSError as e:
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):
return False

e.strerror = f"Unable to load configuration file ({e.strerror})"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ def test_config_missing_file():
assert not app.config.from_file("missing.json", load=json.load, silent=True)


def test_config_enotdir_silent(tmp_path):
"""from_file with silent=True should not raise when a path component
is a file instead of a directory (ENOTDIR)."""
# Create a regular file where a directory is expected in the path.
not_a_dir = tmp_path / "not_a_dir"
not_a_dir.write_text("")
app = flask.Flask(__name__)
app.config.root_path = str(tmp_path)
assert not app.config.from_file(
os.path.join("not_a_dir", "config.json"), load=json.load, silent=True
)


def test_custom_config_class():
class Config(flask.Config):
pass
Expand Down
Loading