dynaconf / dynaconf/dynaconf

[bug] DynaconfFormatError (circular reference) when applying @jinja to alter the same value

Open
#1,425 1 comment 0 reactions 0 assignees Claimed by @pedro-psb View on GitHub
bug
Dominant language
Python
Stars
4.3k
Forks
347
Avg merge
2d 2h
Merged PRs (30d)
1

Description

**Describe the bug**
I apply the following code to make sure that a value is an integer even if defined as string:
`MAIN__STARTYEAR = "@int @jinja {{this.main.startyear | int}}"`
This is part of an toml-file defined via the includes-parameter of `Dynaconf`

Before version 3.3.0 this went well, now it raises a DynaconfFormatError (Circular reference detected in lazy formatting. A value is referencing itself directly or indirectly.) in nodes.py:734

**To Reproduce**
Steps to reproduce the behavior:

1. Having the following folder structure

Project structure

```bash
# /dynaconf_circular/
```

2. Having the following config files:

Config files

**/dynaconf_circular/settings.toml**
```toml
[main]
startyear = "2015"
```
and

**/dynaconf_circular/config_post.toml**
```bash
MAIN__STARTYEAR = "@int @jinja {{this.main.startyear | int}}"
```

3. Having the following app code:

Code

**/dynaconf_circular/config.py**
```python
from dynaconf import Dynaconf

if __name__ == '__main__':
settings_dyna = Dynaconf(
merge_enabled=True,
environments=False,
settings_files=["settings.toml"],
loaders=[
"dynaconf.loaders.toml_loader",
],
includes=["config_post.toml"],
)
print(settings_dyna.main.startyear)
```

4. Executing under the following environment

Execution

```bash

$ python config.py
```

**Expected behavior**
Printing "2015"

**Environment (please complete the following information):**
- OS: Windows 11
- Dynaconf Version 3.3.0

**Additional context**
For the DynaconfFormatError, it would be good to include more context (i.e. the value that is circularly referenced) in the error message!

Contributor guide

Open the contributing guide

Research direction

Reproduce the circular-reference failure with settings.toml, config_post.toml, and config.py, then inspect nodes.py around line 734 to trace the lazy-formatting behavior. Done means the example prints 2015 as expected and the DynaconfFormatError provides more context about the circularly referenced value; an open pull request is already linked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.