You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The has been introduced a change in commit 6aab658 (version 1.2.1) which makes it impossible to test for an not existing attribute on a BaseConfig object instance and use a default using
getattr(base, key, default)
hasattr(base, key)
If the attribute key doesn't exist, there is always thrown a KeyError due to the override of the __getattr__ function on BaseConfig. This is highly impractical and a bigger breaking change in this minor version step.
To Reproduce
Steps to reproduce the behavior:
YAML example:
jobs:
a:
foo: "bar"is_optional: trueb:
foo: "bar"
Results:
File "/home/user/work/scripts/job.py", line ??, in __init__
conf.is_optional if hasattr(conf, 'is_optional') else None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/work/lib/python3.11/site-packages/pyaml_env/base_config.py", line 28, in __getattr__
return self.__dict__[field_name]
~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'is_optional'
Expected behavior
getattr and hasattr should work on BaseConfig without limitations.
Additional context
Python version 3.11
OS Debian 12
The text was updated successfully, but these errors were encountered:
Describe the bug
The has been introduced a change in commit 6aab658 (version 1.2.1) which makes it impossible to test for an not existing attribute on a BaseConfig object instance and use a default using
If the attribute
key
doesn't exist, there is always thrown aKeyError
due to the override of the__getattr__
function onBaseConfig
. This is highly impractical and a bigger breaking change in this minor version step.To Reproduce
Steps to reproduce the behavior:
YAML example:
Results:
Expected behavior
getattr and hasattr should work on BaseConfig without limitations.
Additional context
The text was updated successfully, but these errors were encountered: