Skip to content

gh-149015: avoid iterate-and-delete issue in Bdb.clear_all_file_breaks#149039

Open
AmSach wants to merge 2 commits intopython:mainfrom
AmSach:fix/bdb-clear-all-file-breaks
Open

gh-149015: avoid iterate-and-delete issue in Bdb.clear_all_file_breaks#149039
AmSach wants to merge 2 commits intopython:mainfrom
AmSach:fix/bdb-clear-all-file-breaks

Conversation

@AmSach
Copy link
Copy Markdown

@AmSach AmSach commented Apr 27, 2026

Fix for gh-149015: bdb.Bdb.clear_all_file_breaks() skips breakpoints when multiple share the same (filename, line).

Root cause: iterating a list directly while deleteMe() removes items from that same list causes the loop to skip every other element. For N breakpoints at the same (file, line), floor(N/2) orphans remain.

Fix: one-character change - add slice copy to avoid mutating during iteration:

  • for bp in blist:
  • for bp in blist[:]:

This matches the existing defensive pattern already used in clear_break() (same file, same class).

Files:

  • Lib/bdb.py - the one-character fix
  • Lib/test/test_bdb.py - regression test
  • Misc/NEWS.d/next/Library.rst - news entry

Closes #149015

…-delete bug (pythongh-149015)

When multiple breakpoints share the same (filename, line), iterating the list
directly while calling deleteMe() (which removes from the same list) causes the
loop to skip alternate elements, leaving floor(N/2) orphan breakpoints.

The fix (for bp in blist: → for bp in blist[:]:) matches the existing defensive
pattern already used in clear_break() in the same file.

Added regression test test_clear_all_file_breaks_with_multiple_bps_same_line.
@AmSach AmSach requested a review from gaogaotiantian as a code owner April 27, 2026 07:10
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 27, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 27, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 27, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz picnixz changed the title fix bdb: use slice copy in clear_all_file_breaks to avoid iterate-and-delete bug gh-149015: use slice copy in Bdb.clear_all_file_breaks to avoid iterate-and-delete bug Apr 27, 2026
@picnixz picnixz changed the title gh-149015: use slice copy in Bdb.clear_all_file_breaks to avoid iterate-and-delete bug gh-149015: avoid iterate-and-delete issue in Bdb.clear_all_file_breaks Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bdb.clear_all_file_breaks skips breakpoints when multiple breakpoints share a line

1 participant