Skip to content

Commit

Permalink
Fix set_key creates orphan .env file
Browse files Browse the repository at this point in the history
Changed:
- `set_key` now checks if the `dotenv_path` exists

Fix theskumar#480
  • Loading branch information
TheGeeKing committed Aug 15, 2023
1 parent 3ffcef6 commit 8faa34b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def set_key(
or (quote_mode == "auto" and not value_to_set.isalnum())
)

if not os.path.exists(dotenv_path):
logger.warning("Can't set key to %s - it doesn't exist.", dotenv_path)
return None, key_to_set, value_to_set

if quote:
value_out = "'{}'".format(value_to_set.replace("'", "\\'"))
else:
Expand Down

0 comments on commit 8faa34b

Please sign in to comment.