Skip to content

gh-152228: Fix an assertion failure in str.replace under a limited memory case - #152229

Merged
sobolevn merged 5 commits into
python:mainfrom
sobolevn:issue-152228
Jun 29, 2026
Merged

gh-152228: Fix an assertion failure in str.replace under a limited memory case#152229
sobolevn merged 5 commits into
python:mainfrom
sobolevn:issue-152228

Conversation

@sobolevn

@sobolevnsobolevn commented Jun 25, 2026

Copy link
Copy Markdown
Member

Because test was simple enough and was always 0 as the memory limit, I decided to include it.

@sobolevnsobolevn added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 25, 2026
Comment threadLib/test/test_str.py Outdated
Co-authored-by: Stan Ulbrych <stan@python.org>
@sobolevn

Copy link
Copy Markdown
MemberAuthor

Created #152236 to track Py_TRACE_REFS skips. There are several tests that don't have that.

@@ -0,0 +1 @@
Fix a crash in :meth:`str.replace` under a limited memory situation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't call it a "crash". It's "only" an assertion failure when Python is built in debug mode.

@sobolevnsobolevn changed the title gh-152228: Fix a crash in str.replace under a limited memory casegh-152228: Fix an assertion failure in str.replace under a limited memory caseJun 27, 2026

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@vstinner

Copy link
Copy Markdown
Member

Strange, CI tests pass, but test_str fails when I download the PR locally:

$ ./python -m test test_str -v
...
test test_str crashed -- Traceback (most recent call last):
...
File "/home/vstinner/python/main/Lib/test/test_str.py", line 610, in StrTest
@support.nomemtest
^^^^^^^^^^^^^^^^^
AttributeError: module 'test.support' has no attribute 'nomemtest'. Did you mean '.bigmemtest' instead of '.nomemtest'?

Do it work on your machine? The "Squash and merge" should work around the issue anyway.

@sobolevn
sobolevn enabled auto-merge (squash) June 29, 2026 15:56
@sobolevn

Copy link
Copy Markdown
MemberAuthor

Looks like a forgot to push the merge commit. Did it now :)
Thanks a lot for the reviews!

@vstinner

Copy link
Copy Markdown
Member

Looks like a forgot to push the merge commit. Did it now :)

But it's strange that tests passed on the CI (without the merge commit).

@sobolevn

Copy link
Copy Markdown
MemberAuthor

I copied this exact branch, added assert False to the test, executed it:
Снимок экрана 2026-06-29 в 19 19 58

test_replace_oom failed. It worked correctly for me :)

@sobolevn
sobolevn merged commit c5043dc into python:mainJun 29, 2026
54 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

Copy link
Copy Markdown

GH-152615 is a backport of this pull request to the 3.15 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 29, 2026
@bedevere-app

Copy link
Copy Markdown

GH-152616 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Jun 29, 2026
@bedevere-app

Copy link
Copy Markdown

GH-152617 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Jun 29, 2026
sobolevn added a commit that referenced this pull request Jun 29, 2026
…imited memory case (GH-152229) (#152616)
gh-152228: Fix an assertion failure in `str.replace` under a limited memory case (GH-152229)
(cherry picked from commit c5043dc)
Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn added a commit that referenced this pull request Jun 29, 2026
…imited memory case (GH-152229) (#152615)
gh-152228: Fix an assertion failure in `str.replace` under a limited memory case (GH-152229)
(cherry picked from commit c5043dc)
Co-authored-by: sobolevn <mail@sobolevn.me>
Sign up for freeto 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.

3 participants

@sobolevn@vstinner@StanFromIreland