python / python/cpython

When url and filename are the same, urlretrieve() will wipe out data in the file

Open
#94,767 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

If url and filename points to the same local file, the original file will be replaced by an empty file when executing
tfp = open(filename, 'wb')
and a ContentTooShortError will be raised as the file content is no longer available.
I suppose it should either do nothing or raise an exception during such circumstances.

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 urlretrieve() and reproduce the case where the URL and filename refer to the same local file, focusing on the open(filename, 'wb') path described in the report. Define and verify one consistent outcome for this case—leaving the file unchanged or raising an exception—without losing its original contents.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.