Merge branch 'release/4.10.3' into master

This commit is contained in:
Roman Mogylatov 2021-01-20 09:04:24 -05:00
commit 349c252b50
5 changed files with 3446 additions and 3328 deletions

View File

@ -7,6 +7,13 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
4.10.3
------
- Fix a bug in the ``Configuration`` provider: strict mode didn't work when provider
is overridden by ``None``.
See issue: `#358#issuecomment-761607432 <https://github.com/ets-labs/python-dependency-injector/issues/358#issuecomment-761607432>`_.
Many thanks to `Stefano Frazzetto <https://github.com/StefanoFrazzetto>`_ for reporting the issue.
4.10.2
------
- Fix a bug in ``Resource`` that cause failure when async resource depends on

View File

@ -1,6 +1,6 @@
"""Top-level package."""
__version__ = '4.10.2'
__version__ = '4.10.3'
"""Version number.
:type: str

File diff suppressed because it is too large Load Diff

View File

@ -1471,12 +1471,14 @@ cdef class Configuration(Object):
:return: Option value.
:rtype: Any
"""
keys = selector.split('.')
value = self.__call__()
if value is None:
if self.__strict or required:
raise Error('Undefined configuration option "{0}.{1}"'.format(self.__name, selector))
return None
keys = selector.split('.')
while len(keys) > 0:
key = keys.pop(0)
value = value.get(key, self.UNDEFINED)
@ -1500,9 +1502,9 @@ cdef class Configuration(Object):
:return: Overriding context.
:rtype: :py:class:`OverridingContext`
"""
keys = selector.split('.')
original_value = current_value = deepcopy(self.__call__())
keys = selector.split('.')
while len(keys) > 0:
key = keys.pop(0)
if len(keys) == 0:

View File

@ -214,6 +214,12 @@ class ConfigTests(unittest.TestCase):
with self.assertRaisesRegex(errors.Error, 'Undefined configuration option "config.a"'):
self.config.a()
def test_value_of_undefined_option_with_root_none_in_strict_mode(self):
self.config = providers.Configuration(strict=True)
self.config.override(None)
with self.assertRaisesRegex(errors.Error, 'Undefined configuration option "config.a"'):
self.config.a()
def test_value_of_defined_none_option_in_strict_mode(self):
self.config = providers.Configuration(strict=True)
self.config.from_dict({'a': None})