Skip to content

Conversation

@Delta17920
Copy link
Contributor

Update upload validation to check project lifecycle_status for file conflicts. Provides a more specific error message when the conflict is with an archived project. Fixes #18671

Proof / Test Output

This ss shows the new test (test_upload_fails_with_deleted_project_conflict) and all other tests in the file passing after the code change:
image

Update upload validation to check project lifecycle_status for file conflicts. Provides a more specific error message when the conflict is with an archived project. Fixes pypi#18671
@Delta17920 Delta17920 requested a review from a team as a code owner October 23, 2025 12:42
@di
Copy link
Member

di commented Oct 23, 2025

Thanks for the PR.

Note that whether or not the project is archived has no bearing on whether the given file has been deleted -- an archived project can have 'live' files and an active project can have 'deleted' files.

The actual error message we're trying to improve is this one:

# Check to see if the file that was uploaded exists in our filename log
if request.db.query(
request.db.query(Filename).filter(Filename.filename == filename).exists()
).scalar():
request.metrics.increment(
"warehouse.upload.failed", tags=["reason:filename-reuse"]
)
raise _exc_with_message(
HTTPBadRequest,
"This filename has already been used, use a "
"different version. "
"See "
+ request.help_url(_anchor="file-name-reuse")
+ " for more information.",
)

Given that the previous checks are looking for "live" files (the File model) we should only arrive at this error message in the case if the filename is not 'live' but was previously used and is recorded (the Filename model).

So, we are already distinguishing between 'deleted' and 'live' files when returning this error message, we just need to be more clear in this error message that the file has since been 'deleted' and is no longer 'live'.

@Delta17920
Copy link
Contributor Author

on it

@Delta17920
Copy link
Contributor Author

Thanks for the review, @di ! I've pushed the update. I just changed the error message string in legacy.py and updated the matching test, as you suggested.

@di di enabled auto-merge (squash) October 23, 2025 17:52
@di di merged commit d029959 into pypi:main Oct 23, 2025
29 of 30 checks passed
@Delta17920 Delta17920 deleted the fix-18671-deleted-project-error branch October 24, 2025 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distinguish between 'deleted' and 'live' filenames when refusing upload for duplicate filename

3 participants