Skip to content

set_key / dotenv set report a temp file path when the target's directory doesn't exist #710

Description

@theskumar

When the parent directory of the target file doesn't exist, the error names an internal temp file instead of the .env path:

>>> dotenv.set_key("/tmp/nodir/.env", "A", "1")
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/nodir/.tmp_tjtn0_ek'

The CLI (dotenv -f /tmp/nodir/.env set A 1) prints a full traceback ending in the same message.

Cause: rewrite() in src/dotenv/main.py creates its NamedTemporaryFile in the target's directory before touching the target, so that's what fails first. set_value/unset in cli.py don't catch OSError.

Expected: the library raises an error that names the .env path. The CLI prints a short error and exits with code 2, as stream_file does for get/list. The same probably applies when the directory isn't writable.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions