Skip to content

🐛 fix(config): defer TOML set_env string substitution#3759

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-toml-setenv-recursion
Feb 18, 2026
Merged

🐛 fix(config): defer TOML set_env string substitution#3759
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-toml-setenv-recursion

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Using substitutions like {env_site_packages_dir} inside set_env in TOML format causes a RecursionError because the TOML loader eagerly resolves all string substitutions via Unroll before constructing SetEnv. This creates a circular dependency: set_envenv_site_packages_dircreate_python_env()system_site_packagesenvironment_variablesset_env.

The INI loader already handles this correctly by detecting SetEnv type and deferring string substitution — raw strings are stored as-is and only resolved when individual env vars are accessed via SetEnv.load(). 🔧 This applies the same pattern to the TOML loader: structural TOML constructs (replace: ref, replace: posargs, replace: env) are still resolved during config loading, but string-level {...} substitutions are deferred via a proper TOML-aware replacer passed to SetEnv.use_replacer().

Discovered via pypa/virtualenv#3050 when migrating virtualenv's config from tox.ini to tox.toml. The same configuration that worked in INI format caused infinite recursion in TOML because of the eager substitution.

Closes #3758

The TOML loader eagerly resolved all substitutions in set_env values
via Unroll before constructing SetEnv. When set_env contained
references like {env_site_packages_dir}, this triggered a circular
dependency: set_env → env_site_packages_dir → create_python_env →
system_site_packages → environment_variables → set_env.

The INI loader already handles this by deferring string substitution
for SetEnv values. Apply the same pattern to the TOML loader: resolve
structural TOML constructs (refs, posargs, env lookups) but skip
string-level substitution, providing a real replacer for lazy
per-value resolution.

Closes tox-dev#3758
@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Feb 18, 2026
@gaborbernat gaborbernat enabled auto-merge (squash) February 18, 2026 15:32
@gaborbernat gaborbernat merged commit 5949e93 into tox-dev:main Feb 18, 2026
28 checks passed
@gaborbernat gaborbernat deleted the fix-toml-setenv-recursion branch February 20, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RecursionError when TOML set_env uses {env_site_packages_dir}

1 participant