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 in Objects/typeobject.c
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: felixxm, kj, miss-islington, pablogsal, vstinner
Priority: Keywords: patch

Created on 2021-05-25 11:39 by felixxm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26358 closed kj, 2021-05-25 15:57
PR 26359 merged vstinner, 2021-05-25 16:28
PR 26365 merged miss-islington, 2021-05-25 20:28
Messages (7)
msg394330 - (view) Author: Mariusz Felisiak (felixxm) * Date: 2021-05-25 11:39
We noticed a behavior change in [1]. One of our tests `apps.tests.AppsTests.test_model_clash()`[2] crashes with:

python: Objects/typeobject.c:3219: type_new: Assertion `type != NULL' failed.
Fatal Python error: Aborted

Current thread 0x00007ffa6951a280 (most recent call first):
  File "django/tests/apps/tests.py", line 301 in test_model_clash
  File "cpython/Lib/unittest/case.py", line 549 in _callTestMethod
  File "cpython/Lib/unittest/case.py", line 592 in run
  File "cpython/Lib/unittest/case.py", line 652 in __call__
  File "django/django/test/testcases.py", line 283 in _setup_and_call
  File "django/django/test/testcases.py", line 247 in __call__
  File "cpython/Lib/unittest/suite.py", line 122 in run
  File "cpython/Lib/unittest/suite.py", line 84 in __call__
  File "cpython/Lib/unittest/runner.py", line 176 in run
  File "django/django/test/runner.py", line 705 in run_suite
  File "django/django/test/runner.py", line 772 in run_tests
  File "django/tests/./runtests.py", line 332 in django_tests
  File "django/tests/./runtests.py", line 596 in <module>
Aborted (core dumped)

This can be an issue is our test which is quite tricky. I will try to investigate it.

[1] https://github.com/python/cpython/commit/ecf14e6557c6e4f7af9c0d6460d31fe121c22553
[2] https://github.com/django/django/blob/7e51893911237dfca9294e3ca12163ff813fb656/tests/apps/tests.py#L274-L309
msg394350 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-05-25 13:42
Can you please try removing the `assert(type != NULL);` line at https://github.com/python/cpython/blob/main/Objects/typeobject.c#L3313 and see if it works for you? I suspect that `winner->tp_new()` may sometimes fail and *should* return NULL to indicate that in those cases, so the assert may not always hold.
msg394371 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-05-25 15:38
Alright, I got a minimum reproducible example:

class XBase(type):
    def __new__(cls, name, bases, attrs, **kwargs):
        attrs.pop('__module__')
        return super().__new__(cls, name, bases, attrs, **kwargs)

class X(metaclass=XBase): ...

type('A', (X, ), {})


This triggers it, sending patch soon.
msg394375 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-25 16:30
> We noticed a behavior change in [1].

Hey, well done bisection, you're right, it's a regression of my large type_new() refactoring in bpo-43770.

I wrote PR 26359 to fix it.
msg394393 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-25 20:28
New changeset bd199e72fb60a8ff001a023f23925092a290be91 by Victor Stinner in branch 'main':
bpo-44232: Fix type_new() error reporting (GH-26359)
https://github.com/python/cpython/commit/bd199e72fb60a8ff001a023f23925092a290be91
msg394426 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-26 09:31
New changeset 7b3b6982a5683f5146ede58a448d3edb777e501b by Miss Islington (bot) in branch '3.10':
bpo-44232: Fix type_new() error reporting (GH-26359) (GH-26365)
https://github.com/python/cpython/commit/7b3b6982a5683f5146ede58a448d3edb777e501b
msg394428 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-26 10:23
Ok, it's now fixed in 3.10 and main branches. Thanks for the bug report, and thanks Ken Jin for your PR ;-)
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88398
2021-05-26 10:23:18vstinnersetstatus: open -> closed
priority: release blocker ->
messages: + msg394428

resolution: fixed
stage: patch review -> resolved
2021-05-26 09:31:07vstinnersetmessages: + msg394426
2021-05-25 20:28:43miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24956
2021-05-25 20:28:19vstinnersetmessages: + msg394393
2021-05-25 16:30:44vstinnersetmessages: + msg394375
2021-05-25 16:28:15vstinnersetpull_requests: + pull_request24951
2021-05-25 15:57:33kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24950
2021-05-25 15:38:00kjsetmessages: + msg394371
2021-05-25 14:26:16pablogsalsetpriority: normal -> release blocker
nosy: + pablogsal
2021-05-25 13:42:43kjsetnosy: + kj
messages: + msg394350
2021-05-25 11:39:15felixxmcreate