Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Attribute error when accessing formatted value in layered config #482

Closed
billcrook opened this issue Dec 4, 2020 · 3 comments · Fixed by #527
Closed

[bug] Attribute error when accessing formatted value in layered config #482

billcrook opened this issue Dec 4, 2020 · 3 comments · Fixed by #527
Assignees
Labels

Comments

@billcrook
Copy link

Describe the bug
Attribute error when accessing settings value in layered configuration with multiple settings files.

Exception
Traceback (most recent call last):
  File "app.py", line 11, in <module>
    assert settings['s3_url'] == expected_value # fails
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/functional.py", line 17, in inner
    return func(self._wrapped, *args)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/base.py", line 285, in __getitem__
    value = self.get(item, default=empty)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/base.py", line 419, in get
    data = (parent or self.store).get(key, default)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/boxing.py", line 15, in evaluate
    value = f(dynabox, item, *args, **kwargs)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/boxing.py", line 64, in get
    return super(DynaBox, self).get(item, default, *args, **kwargs)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/vendor/box/box.py", line 109, in get
    return B[C]
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/boxing.py", line 23, in evaluate
    return recursively_evaluate_lazy_format(value, settings)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/__init__.py", line 355, in recursively_evaluate_lazy_format
    value = value(settings)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/parse_conf.py", line 176, in __call__
    return self.formatter(self.value, **self.context)
  File "/home/user/dev/venv/lib/python3.7/site-packages/dynaconf/utils/parse_conf.py", line 138, in __call__
    return self.function(value, **context)
AttributeError: 'Settings' object has no attribute 's3_protocol'

To Reproduce
Steps to reproduce the behavior:

  1. Having the following folder structure
Project structure
$ ls
.  ..  app.py  conf-test-default.toml  conf-test-layer.toml
  1. Having the following config files:
Config files

conf-test-default.toml

s3_protocol = 's3a'
s3_url = '@format {this.s3_protocol}://{this.s3_bucket}'

and

conf-test-layer.toml

s3_bucket = 'kewl_bucket'
  1. Having the following app code:
Code

app.py

from dynaconf import Dynaconf

settings_files = ['conf-test-default.toml', 'conf-test-layer.toml']

settings = Dynaconf(settings_files=settings_files)

expected_value = 's3a://kewl_bucket'

assert settings.s3_url == expected_value # succeeds

assert settings['s3_url'] == expected_value # fails

assert settings.get('s3_url', default='s3://default') == expected_values # fails

assert settings('s3_url', cast=str) == expected_value # fails
  1. Executing under the following environment
Execution
$ python app.py

Expected behavior
I would expect all documented settings access methods to function properly.

Environment (please complete the following information):

@billcrook billcrook added the bug label Dec 4, 2020
@billcrook
Copy link
Author

It seems that accessing via getitem differs from via getattr. Specifically I see that __getattr__ calls recursively_evaluate_lazy_format whereas __getitem__ does not.

@rochacbruno
Copy link
Member

I think this issue was solved in #405 I will double check.

@rochacbruno rochacbruno self-assigned this Feb 28, 2021
rochacbruno added a commit that referenced this issue Feb 28, 2021
* Fix #482 - formatter using both upper and lowercase access

Fix #482

* add more testes covering nested formatting
@billcrook
Copy link
Author

👍

rochacbruno added a commit that referenced this issue Mar 1, 2021
Shortlog of commits since last release:

    Bruno Rocha (11):
          Release version 3.1.2
          Fix #445 casting on dottet get. (#446)
          Fix docs regarding --django argument on cli (#477)
          Fix #521 - FlaskDynaconf should raise KeyError for non existing keys (#522)
          Case insensitive envvar traversal (#524)
          Allow load_file to accept pathlib.Path (#525)
          Allow Title case lookup and validation. (#526)
          Fix #482 - formatter case insensitive (#527)
          Fix #449 - Django lazy templating Fix #449 (#528)
          Added a test to reproduce #492 (not able to reproduce) (#530)
          Fix #511 allow user to specify loaders argument to execute_loaders (#531)

    FrankBattaglia (1):
          Specify flask extension initializers by entry point object reference (#456)

    Ilito Torquato (3):
          fix merging hyperlink to fix  #454 (#458)
          Changed enabled_core_loaders elements to be upper case to fix #455 (#457)
          Fix doc secrets from vault #403 (#459)

    Marcelo Lino (1):
          Add __contains__ to Dynaconf (#502)

    Michal Odnous (1):
          Fix: Environment variables filtering #470 (#474)

    dependabot-preview[bot] (5):
          Bump mkdocs-material from 6.0.2 to 6.1.0 (#453)
          Bump mkdocs-git-revision-date-localized-plugin from 0.5.2 to 0.7.3 (#463)
          Bump mkdocs-material from 6.1.0 to 6.1.5 (#473)
          Bump mkdocs-versioning from 0.2.1 to 0.3.1 (#475)
          Bump mkdocs-material from 6.1.5 to 6.1.6 (#476)

    mirrorrim (1):
          Fix reading secret from Vault kv v2 (#483) (#487)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants