theskumar / theskumar/python-dotenv

using set_key on a file over the network results in error

Open
#411 0 comments 0 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

When trying to use set_key to create a .env file if one dosn't exist the first line works great but the second line always fails with this line because of the way that windows handles moving files across networks.

OSError: [WinError 17] The system cannot move the file to a different disk drive: 'C:\\Users\\[my username]\\AppData\\Local\\Temp\\tmpk0c72zk9' ->'N:\\[my username]\\Documents\\[project name]\\.env'

code that generates the error

# load the stuff that shouldn't be given out
user_config = dotenv_values(env_file_path)

if len(user_config) == 0:
    module_logger.fatal('.env file with all of the needed stuff was empty. Creating it then exiting')
    module_logger.debug(f'creating the .env file at {env_file_path.absolute()}')
    env_file_path.touch()

    module_logger.debug('setting the values inside the .env file')
    set_key(env_file_path,'username','username') # <-- this line gets written to the file
    set_key(env_file_path,'password','password') # <-- line that fails
    set_key(env_file_path,'client_id','client id (tools>options>system settings)')
    set_key(env_file_path,'client_secret','client secret (tools>options>system settings)')
    sys.exit(1)

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 at the set_key entry point and reproduce the shown sequence with env_file_path on a Windows network path. Compare the first and second calls and verify that repeated updates can create or update the .env file without the reported cross-drive error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.