Open
Description
I noticed that the configuration provider does silently accept invalid paths in the following case, even if required=True is set:
/tmp/myfolder/existing_file.py/invalid.ini
.
Such an invalid path might be caused by mistaking a file for a directory and then appending another filename. If the first file in the path exists, the configuration provider implementation seems to consider the whole path valid.
In this case, no exception is thrown. Here is a minimum working example to reproduce this situation:
from pathlib import Path
from tempfile import mkdtemp
from dependency_injector import containers, providers
temporary_dir = Path(mkdtemp())
testfile = temporary_dir/'test.file'
testfile.write_bytes(b'blabla')
some_invalid_path = testfile/'my_configuration.ini'
container = containers.DynamicContainer()
container.config = providers.Configuration()
container.config.from_ini(some_invalid_path, required=True)
print(f"Even though '{some_invalid_path.as_posix()}'.exists is '{some_invalid_path.exists()}', we got not exception.")
On my machine, this outputs:
Even though '/tmp/tmp6wyg0ft9/test.file/my_configuration.ini'.exists is 'False', we got not exception.
Metadata
Metadata
Assignees
Labels
No labels