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

Fix regression with multiple env substitutions for the same key #2873

Merged
merged 3 commits into from Jan 16, 2023

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Jan 16, 2023

Fix regression introduced in 4.3.0 which occured when a substitution expression for an environment variable that had previously been substituted appears in the ini file after a substitution expression for a different environment variable.

This situation erroneously resulted in an exception about "circular chain between set" of those variables.

Before the substitution parser rewrite, args was being copied in the replace function:

replaced = _replace_match(conf, loader, to_replace, args.copy())

This patch restores the previous behavior by copying conf_args at the beginning of _replace_match.

This change also preserves recursive chain detection logic by passing the copied conf_args back into replace when recursively expanding a previous replacement so that any values saved in the chain during the previous replace are present for the recursive replace (test case added in previous commit).

Fix #2869

Thanks for contribution

Please, make sure you address all the checklists (for details on how see
development documentation)!

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

When the same variables appear across separate substitutions, it should not
trigger chain detection.
Ensure that a true circular chain of env vars logs the correct error message.
Before the replacement parser rewrite, args was being copied in the `replace`
function:

https://github.com/tox-dev/tox/blob/955a7fb8864a9e682ec91589e0c10115ab6fa6a5/src/tox/config/loader/ini/replace.py#L35

This restores the previous behavior by copying `conf_args` at the beginning of
`_replace_match`.

This change also preseves chain detection logic by passing the copied
`conf_args` back into `replace` when recursively expanding a previous
replacement so that any values saved in the chain during the previous replace
are present for the recursive replace (test case added in previous commit).

Fix tox-dev#2869
@gaborbernat gaborbernat merged commit 0006a12 into tox-dev:main Jan 16, 2023
@masenf masenf deleted the multiple-env-repl branch January 16, 2023 17:05
nedbat added a commit to nedbat/coveragepy that referenced this pull request Jan 16, 2023
descope bot added a commit to descope/django-descope that referenced this pull request Jan 30, 2023
This PR contains the following updates:

| Package | Type | Update | Change | Pending |
|---|---|---|---|---|
| [tox](https://togithub.com/tox-dev/tox)
([changelog](https://tox.wiki/en/latest/changelog.html)) | dev | patch |
`4.3.1` -> `4.3.2` | `4.4.2` (+5) |

---

### Release Notes

<details>
<summary>tox-dev/tox</summary>

### [`v4.3.2`](https://togithub.com/tox-dev/tox/releases/tag/4.3.2)

[Compare Source](https://togithub.com/tox-dev/tox/compare/4.3.1...4.3.2)

#### What's Changed

- Fix rendering of `version_added` by
[@&#8203;kurtmckee](https://togithub.com/kurtmckee) in
[tox-dev/tox#2867
- Fix a RestructuredText typo by
[@&#8203;kurtmckee](https://togithub.com/kurtmckee) in
[tox-dev/tox#2866
- Fix typos in `{tox_root}` variable name by
[@&#8203;kurtmckee](https://togithub.com/kurtmckee) in
[tox-dev/tox#2871
- Fix regression with multiple env substitutions for the same key by
[@&#8203;masenf](https://togithub.com/masenf) in
[tox-dev/tox#2873
- Fix a incorrect config key name by
[@&#8203;kurtmckee](https://togithub.com/kurtmckee) in
[tox-dev/tox#2868

#### New Contributors

- [@&#8203;kurtmckee](https://togithub.com/kurtmckee) made their first
contribution in
[tox-dev/tox#2867

**Full Changelog**: tox-dev/tox@4.3.1...4.3.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDEuMCIsInVwZGF0ZWRJblZlciI6IjM0LjEwMS4wIn0=-->

Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple env subsitutions broken in tox 4.3
2 participants