Skip to content

dynaconf.vendor.box.exceptions.BoxKeyError while following the example for envvar_prefix #722

@mvadu

Description

@mvadu

version: '3.2'

services:
I am following the env variable example from https://www.dynaconf.com/envvars/#custom-prefix , after exporting the variables in the shell, running this example code.

from dynaconf import Dynaconf

settings = Dynaconf(envvar_prefix="PEANUT")


assert settings.USER == "admin"
assert settings.PASSWD == 1234
assert settings.db.name == "foo"
assert settings.db.port == 2000
assert settings.db.scheme == 'main'

trying to access settings.db.name above throws an exception

   runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/usr/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/media/shared/docker/custom_images/mi_atc_reader/test.py", line 8, in <module>
    assert settings.db.name == "foo"
  File "/home/mvadu/.local/lib/python3.8/site-packages/dynaconf/utils/boxing.py", line 16, in evaluate
    value = f(dynabox, item, *args, **kwargs)
  File "/home/mvadu/.local/lib/python3.8/site-packages/dynaconf/utils/boxing.py", line 39, in __getattr__
    return super(DynaBox, self).__getattr__(n_item, *args, **kwargs)
  File "/home/mvadu/.local/lib/python3.8/site-packages/dynaconf/vendor/box/box.py", line 177, in __getattr__
    raise BoxKeyError(str(E)) from _A
dynaconf.vendor.box.exceptions.BoxKeyError: "'DynaBox' object has no attribute 'NAME'"

I could not find any open issues on this, I am not sure if its a true regression or its something off with my setup.

$ python --version
Python 3.8.10
$ pip freeze | grep dynaconf
dynaconf==3.1.7

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions