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] Deleting entry raises an error #1042

Open
antoine-gallix opened this issue Jan 19, 2024 · 0 comments
Open

[bug] Deleting entry raises an error #1042

antoine-gallix opened this issue Jan 19, 2024 · 0 comments
Labels

Comments

@antoine-gallix
Copy link

Describe the bug

As part of my tests, I want to temporarily remove a section of my config to ensure my application reacts properly to this section being missing.

I try del config.some_section which produces the following error:

In [1]: config
Out[1]: <dynaconf.base.LazySettings object at 0x7fe6597e4c50>

In [2]: config.database
Out[2]: <Box: {'host': 'some_host', 'port': 5431, 'user': 'postgres', 'password': 'secret', 'name': 'the_data'}>

In [3]: del config.database
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 del config.database

File ~/dev/prospect/dataworker/.venv/lib/python3.11/site-packages/dynaconf/utils/functional.py:64, in LazyObject.__delattr__(self, name)
     62 if self._wrapped is empty:
     63     self._setup()
---> 64 delattr(self._wrapped, name)

File ~/dev/prospect/dataworker/.venv/lib/python3.11/site-packages/dynaconf/base.py:300, in Settings.__delattr__(self, name)
    298 self._deleted.add(name)
    299 if hasattr(self, name):
--> 300     super().__delattr__(name)

AttributeError: 'Settings' object has no attribute 'database'

In [4]: config.database
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 config.database

File ~/dev/prospect/dataworker/.venv/lib/python3.11/site-packages/dynaconf/base.py:124, in LazySettings.__getattr__(self, name)
    122     self._setup()
    123 if name in self._wrapped._deleted:  # noqa
--> 124     raise AttributeError(
    125         f"Attribute {name} was deleted, " "or belongs to different env"
    126     )
    128 if name not in RESERVED_ATTRS:
    129     lowercase_mode = self._kwargs.get(
    130         "LOWERCASE_READ_FOR_DYNACONF",
    131         default_settings.LOWERCASE_READ_FOR_DYNACONF,
    132     )

AttributeError: Attribute database was deleted, or belongs to different env

To Reproduce

Try to delete a section of a dynaconf config object. My config object is not special, I create it using the standard method. It's an instance of dynaconf.base.LazySettings. The section in question do exist before I try to delete it.

Expected behavior

I expect the command to be successful, not throw an error, and subsequent attempts to access this section to fail as if it had never been configured in the first place.

Environment (please complete the following information):

  • Dynaconf Version: 3.2.4

Comments

It looks that there is some code written to handle deleting a section of the config but

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant