theskumar / theskumar/python-dotenv

set_key creates orphan .env file

Open
#480 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.9k
Forks
581
PR merge metrics
No merged PRs in 30d

Description

set_key states "If the .env path given doesn't exist, fails instead of risking creating an orphan .env somewhere in the filesystem".

set_key has no check if the file exists. As it uses rewrite which if path passed is not a file, it creates an empty file.

if not os.path.isfile(path):
        with open(path, mode="w", encoding=encoding) as source:
            source.write("")

https://github.com/theskumar/python-dotenv/blob/3ffcef60d10813b72ecf85d5941d51b0207cd40e/src/dotenv/main.py#L134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with set_key and rewrite in src/dotenv/main.py, especially the file-existence behavior described in the issue. Reproduce set_key with a nonexistent .env path and inspect the related tests or test entry points. Done means a missing path fails without creating an orphan file, while existing-file behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.