This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Crash when setting attribute with string subclass as the name (--with-pydebug)
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, Mark.Shannon, methane, ronaldoussoren, xtreak
Priority: normal Keywords: patch

Created on 2022-03-02 21:30 by ronaldoussoren, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31658 merged Mark.Shannon, 2022-03-03 12:09
PR 31718 merged Dennis Sweeney, 2022-03-07 07:06
Messages (7)
msg414386 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2022-03-02 21:30
The script below fails with an assertion error with python 3.11a5+ (current trunk) when build with --with-pydebug:

# BEGIN OF FILE
class String(str):
    __slots__ = ()

name = String("hello")

class Bag:
    pass

o = Bag()
setattr(o, name, 42)

# END OF FILE

Error output:

% /tmp/py311/bin/python3 -Xdev str.py                                                                                                                 (master)pyobjc-8
Assertion failed: (PyUnicode_CheckExact(name)), function _PyObject_StoreInstanceAttribute, file dictobject.c, line 5426.
Fatal Python error: Aborted

Current thread 0x0000000100a98580 (most recent call first):
  File "/Users/ronald/Projects/pyobjc-8/pyobjc-core/str.py", line 10 in <module>
zsh: abort      /tmp/py311/bin/python3 -Xdev str.py
msg414387 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2022-03-02 21:33
A hard crash seems wrong to me, and I'm not convinced yet that checking that the type of the attribute name is exactly string is correct.

Found while debugging a crash in PyObjC's testsuite, PyObjC uses a subclass of str to represent Objective-C strings.  Using such instances works fine in practice, but causes a crash in a --with-pydebug build due to this assertion.
msg414400 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-03 02:35
a8b9350964f43cb648c98c179c8037fbf3ff8a7d is the first bad commit
commit a8b9350964f43cb648c98c179c8037fbf3ff8a7d
Author: Mark Shannon <mark@hotpy.org>
Date:   Wed Oct 13 14:19:34 2021 +0100

    bpo-45340: Don't create object dictionaries unless actually needed (GH-28802)

    * Never change types' cached keys. It could invalidate inline attribute objects.

    * Lazily create object dictionaries.

    * Update specialization of LOAD/STORE_ATTR.

    * Don't update shared keys version for deletion of value.

    * Update gdb support to handle instance values.

    * Rename SPLIT_KEYS opcodes to INSTANCE_VALUE.
msg414515 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-04 11:32
New changeset 03c2a36b2bd2d4469160d1607619ee144175d753 by Mark Shannon in branch 'main':
bpo-46903: Handle str-subclasses in virtual instance dictionaries. (GH-31658)
https://github.com/python/cpython/commit/03c2a36b2bd2d4469160d1607619ee144175d753
msg414616 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-06 12:17
Ronald, does PR 31658 fix your issue?
msg414624 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2022-03-06 20:19
Your PR fixed the issue for me.
msg414640 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2022-03-07 06:50
The PR introduced some deprecation warnings in tests.

./python -Wall -m test test_unicode               
0:00:00 load avg: 1.54 Run tests sequentially
0:00:00 load avg: 1.54 [1/1] test_unicode
/home/karthikeyan/stuff/python/cpython/Lib/test/test_unicode.py:3058: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(o.name, 1)
/home/karthikeyan/stuff/python/cpython/Lib/test/test_unicode.py:3060: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(list(o.__dict__), [name])
/home/karthikeyan/stuff/python/cpython/Lib/test/test_unicode.py:3067: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(o.name2, 3)
/home/karthikeyan/stuff/python/cpython/Lib/test/test_unicode.py:3069: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(list(o.__dict__), [name, name2])

== Tests result: SUCCESS ==

1 test OK.

Total duration: 952 ms
Tests result: SUCCESS
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91059
2022-03-07 07:06:38Dennis Sweeneysetpull_requests: + pull_request29833
2022-03-07 06:50:00xtreaksetnosy: + xtreak
messages: + msg414640
2022-03-06 20:19:52ronaldoussorensetstatus: open -> closed
resolution: fixed
messages: + msg414624

stage: resolved
2022-03-06 12:17:17Mark.Shannonsetmessages: + msg414616
stage: patch review -> (no value)
2022-03-04 11:32:15Mark.Shannonsetmessages: + msg414515
2022-03-03 12:09:24Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29776
2022-03-03 03:22:13methanesetnosy: + methane
2022-03-03 02:35:36Dennis Sweeneysetnosy: + Mark.Shannon, Dennis Sweeney
messages: + msg414400
2022-03-02 21:33:41ronaldoussorensetmessages: + msg414387
2022-03-02 21:30:36ronaldoussorencreate