Skip to content

An entry with both unset and skip-if-set removes an existing variable #329

Closed

Description

@gaborbernat

An entry marked both unset and skip-if-set removes the variable even when it already exists. With KEEP exported, the INI entry D:U:KEEP or the TOML entry KEEP = { unset = true, skip_if_set = true } starts the session without KEEP. The README says skip_if_set leaves an existing variable unchanged and that flags combine in any order.

Affected code

Mechanism

_apply_entries tests entry.unset first and reaches the skip_if_set check only for entries that are not unset. Neither parser rejects the combination.

Reproduction

repro.sh

cd "$(mktemp -d)"
printf '[pytest]\nenv =\n    D:OTHER=config-default\n    D:U:KEEP\n' > pytest.ini
cat > test_env.py <<'PY'
import os


def test_env() -> None:
    print({name: os.environ.get(name) for name in ("OTHER", "KEEP")})
PY
OTHER=caller-value KEEP=caller-value pytest -q -s

Run with sh repro.sh at 3ebb6b4872fd0e450b6670d529e375e11c218e61, with pytest 9.2.0, python-dotenv 1.2.4 and CPython 3.14 on Linux:

{'OTHER': 'caller-value', 'KEEP': None}
.
1 passed in 0.00s

Expected: KEEP is caller-value, like OTHER.

Impact

A variable the caller exported, and the entry said to keep, is missing from the session.

  • Reproducibility: easy. One command with default options.
  • Real-world exposure: unlikely. The two flags contradict each other when the variable is unset, so few configurations combine them.

Credits

Reported by Anthropic's OSS Scanner: ANT-2026-1TT2R7UY.

Activity

  1. added
    bug
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions