Skip to content

feat: easier delete version script#2077

Open
joshuarli wants to merge 3 commits into
mainfrom
easier-delete-version
Open

feat: easier delete version script#2077
joshuarli wants to merge 3 commits into
mainfrom
easier-delete-version

Conversation

@joshuarli
Copy link
Copy Markdown
Member

@joshuarli joshuarli commented Apr 21, 2026

was able to remove taskbroker-client 26.5.0 with ./bin/delete-version taskbroker-client 26.5.0 (dry-run shows a diff then pass --execute to confirm)

todo: fix cosmetically wrong latest version issue (https://pypi.devinfra.sentry.io/simple/taskbroker-client/index.html)

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 33de2cf. Configure here.

Comment thread bin/delete-version
new_packages_json_path,
new_index_path,
):
f.unlink(missing_ok=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally block crashes on undefined index_orig_path

High Severity

When --execute is passed and no matching wheels are found, return 1 at line 111 triggers the finally block. At that point, index_orig_path (assigned at line 126) has never been defined, causing an UnboundLocalError. The same crash occurs if any exception is raised between lines 93–125. This masks the original error/exit and leaves temp files behind instead of cleaning up.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 33de2cf. Configure here.

Comment thread bin/delete-version
Comment on lines +185 to +193
finally:
if args.execute:
for f in (
packages_json_path,
index_orig_path,
new_packages_json_path,
new_index_path,
):
f.unlink(missing_ok=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The script can crash with a NameError in the finally block if it exits early with --execute, because index_orig_path may not be defined before the cleanup code is run.
Severity: CRITICAL

Suggested Fix

Initialize index_orig_path to None before the try block. In the finally block, check if index_orig_path is not None and exists before attempting to access or unlink it. This ensures the variable always exists and prevents the NameError in realistic failure scenarios.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: bin/delete-version#L185-L193

Potential issue: The `finally` block in `bin/delete-version` attempts to clean up
temporary files. However, it references the `index_orig_path` variable, which is only
defined on line 126 within the `try` block. If the script exits early (e.g., at line 111
when no matching wheels are found) or if an exception occurs before line 126, the
`finally` block is still executed. When this happens with the `--execute` flag, the code
attempts to access the undefined `index_orig_path`, causing a `NameError` and crashing
the script. This leaves temporary files like `packages.json.orig` and `*.new` on disk.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

1 participant