Skip to content

Conversation

@methane
Copy link
Member

@methanemethane commented Dec 30, 2025

When iserting non unicode key into split table, matching Unicode key may be in the shared split table without its value.

When iserting non unicode key into split table, matching Unicode key may be in the shared split table without its value.
@methanemethane requested a review from CopilotDecember 30, 2025 06:54
@methanemethane added interpreter-core (Objects, Python, Grammar, and Parser dirs) needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Dec 30, 2025
Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in the CPython dictionary implementation when inserting a non-str key (specifically a str subclass) into a split table dictionary where the key matches an existing key in the shared split table but has no corresponding value in the instance dictionary yet.

Key Changes:

  • Fixed the logic in insertdict() to check old_value == NULL instead of ix == DKIX_EMPTY to properly handle split tables where a key exists without a value
  • Added explanatory comments documenting this edge case behavior
  • Added test coverage for the specific scenario that was causing the crash

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
Objects/dictobject.cFixed the condition check in insertdict() to use old_value == NULL instead of ix == DKIX_EMPTY and added clarifying comments about split table behavior
Misc/NEWS.d/next/Core_and_Builtins/2025-12-30-06-48-48.gh-issue-143189.in_sv2.rstAdded changelog entry describing the crash fix
Lib/test/test_dict.pyAdded new test case test_split_table_insert_with_str_subclass to verify the fix works correctly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

obj2 = MyClass()
d = obj2.__dict__
d[MyStr("attr1")] = 2
assert isinstance(list(d)[0], MyStr)
Copy link

CopilotAIDec 30, 2025

Choose a reason for hiding this comment

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

Use unittest assertion method instead of bare assert statement. This ensures the test properly reports failures with helpful messages and follows unittest best practices. Replace with self.assertTrue(isinstance(list(d)[0], MyStr)).

Suggested change
assertisinstance(list(d)[0], MyStr)
self.assertTrue(isinstance(list(d)[0], MyStr))

Copilot uses AI. Check for mistakes.
@hugovkhugovk merged commit 43c7658 into python:mainJan 12, 2026
50 checks passed
@miss-islington-app
Copy link

Thanks @methane for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @methane and @hugovk, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 43c76587c1ba2c3937fa6834db10cffc604e39e0 3.14 

@miss-islington-app
Copy link

Sorry, @methane and @hugovk, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 43c76587c1ba2c3937fa6834db10cffc604e39e0 3.13 

@hugovk
Copy link
Member

@methane Please can you check the backports?

reidenong pushed a commit to reidenong/cpython that referenced this pull request Jan 12, 2026
@methanemethane deleted the fix-143189-dict-insert branch January 13, 2026 04:49
@bedevere-app
Copy link

GH-143771 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 Jan 13, 2026
@bedevere-app
Copy link

GH-143772 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 Jan 13, 2026
methane added a commit to methane/cpython that referenced this pull request Jan 13, 2026
@methanemethane added the type-crash A hard crash of the interpreter, possibly with a core dump label Jan 13, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@methane@hugovk@colesbury