Skip to content

Configuration Provider does not enforce required=True for invalid Paths #670

Open
@jakicoll

Description

@jakicoll

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions