Skip to content

Commit 8faa34b

Browse files
committed
Fix set_key creates orphan .env file
Changed: - `set_key` now checks if the `dotenv_path` exists Fix theskumar#480
1 parent 3ffcef6 commit 8faa34b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/dotenv/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ def set_key(
166166
or (quote_mode == "auto" and not value_to_set.isalnum())
167167
)
168168

169+
if not os.path.exists(dotenv_path):
170+
logger.warning("Can't set key to %s - it doesn't exist.", dotenv_path)
171+
return None, key_to_set, value_to_set
172+
169173
if quote:
170174
value_out = "'{}'".format(value_to_set.replace("'", "\\'"))
171175
else:

0 commit comments

Comments
 (0)