[bug] `redis_loader` usage inconsistent with other loaders
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 347
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 1
Description
**Describe the bug**
Writing to Redis via [loaders.write('redis'..)](https://github.com/dynaconf/dynaconf/blob/2f9a15500f3f254a69eb1a7485387c6e1f259731/dynaconf/loaders/__init__.py#L437) results in the `'redis'` string being passed to [redis_loader.write()](https://github.com/dynaconf/dynaconf/blob/2f9a15500f3f254a69eb1a7485387c6e1f259731/dynaconf/loaders/redis_loader.py#L78) rather than the expected settings obj. This causes the error:
```
AttributeError: 'str' object has no attribute 'REDIS_ENABLED_FOR_DYNACONF'
```
Its possible that, unlike with other loaders, the intended usage of the `redis_loader` is to call `redis_loader.write()` explicitly - but after noticing that I was unable to write directly to Redis from `__setattr__` (ie. settings.param = value) I figured I'd pass thing along just in case it is a bug.
**To Reproduce**
Steps to reproduce the behavior:
1. Having the following folder structure
Project structure
```bash
# /test_dir/
#├── config.py
#├── settings.toml
#└── test.py
```
2. Having the following config files:
Config files
**/test_dir/settings.toml**
```toml
[prod]
param1 = "test"
```
3. Having the following app code:
Code
**/test_dir/test.py**
```python
from config import settings
from dynaconf.utils.boxing import DynaBox
from dynaconf import loaders
def update_persistent_config(key,value):
# identify persistent environment
env = settings.get("ENV_FOR_DYNACONF", "default value")
data = settings.as_dict(env=env)
if key in data:
data[key] = value
loaders.write('redis', DynaBox(data).to_dict(), env=env)
if __name__ == "__main__":
update_persistent_config("param1", "test1")
```
4. Executing under the following environment
Execution
```bash
> pip freeze
async-timeout==5.0.1
dynaconf==3.2.10
pathlib==1.0.1
redis==5.2.1
toml==0.10.2
> python --version
Python 3.8.10
$ python /test_dir/test.py
```
**Expected behavior**
A clear and concise description of what you expected to happen.
- 'redis' resolves to redis_loader module [here](https://github.com/dynaconf/dynaconf/blob/2f9a15500f3f254a69eb1a7485387c6e1f259731/dynaconf/loaders/__init__.py#L437)
- Settings conditionally passed to redis_loader [here](https://github.com/dynaconf/dynaconf/blob/2f9a15500f3f254a69eb1a7485387c6e1f259731/dynaconf/loaders/redis_loader.py#L78)
**Environment (please complete the following information):**
- OS: Linux/Ubuntu 20.04 LTS
- Dynaconf Version 3.2.10
**Additional context**
Potentially relevant discussion question: [Link](https://github.com/dynaconf/dynaconf/discussions/1262)
Contributor guide
Assessment
This issue has not been assessed yet.