fix: handle ENOTDIR in Config.from_file() with silent=True

`from_pyfile()` correctly suppresses `ENOTDIR` when `silent=True`,
but `from_file()` was missing it. This caused an `OSError` when a
path component is a regular file instead of a directory (e.g.
`~/.myapp` is a file and loading `~/.myapp/config.toml`).
This commit is contained in:
Apoorv Darshan 2026-02-18 21:20:31 +05:30
parent d98eb69a35
commit 7d7fdbb07a
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -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