[Django] #36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13

6 views
Skip to first unread message

Django

unread,
Jan 2, 2025, 6:53:53 AMJan 2
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Type: New
| feature
Status: new | Component: Testing
| framework
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Python 3.13 added support for navigating between chained exceptions in pdb
with [https://docs.python.org/3.14/library/pdb.html#pdbcommand-exceptions
the new 'exceptions' command].

Currently, using `test --pdb` does not allow this navigation, failing with
this message:

{{{
(Pdb) exceptions
Did not find chained exceptions. To move between exceptions,
pdb/post_mortem must be given an exception object rather than a traceback.
}}}

`PDBDebugResult` currently passes `pdb.post_mortem()` the traceback
object. But it turns out that the pdb changes in 3.13 also allow passing
an exception here, which is currently undocumented but I
[https://github.com/python/cpython/pull/128410 submitted a PR].

If we switch to passing the exception, it enables switching between
chained exceptions:

{{{
> /.../django/core/management/commands/dumpdata.py(285)handle()
-> raise CommandError("Unable to serialize database: %s" % e)
(Pdb) exceptions
0 TypeError("string argument expected, got 'bytes'")
> 1 CommandError("Unable to serialize database: string argument
expected, got 'by...
(Pdb) exceptions 0
> /.../django/core/management/base.py(181)write()
-> self._out.write(style_func(msg))
(Pdb)
}}}

(I actually made this change to debug a chained exception failure whilst
working on #36056.)
--
Ticket URL: <https://code.djangoproject.com/ticket/36057>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 2, 2025, 6:56:37 AMJan 2
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* has_patch: 0 => 1
* owner: (none) => Adam Johnson
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:1>

Django

unread,
Jan 2, 2025, 7:02:08 AMJan 2
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Johnson):

pytest is already taking advantage of this “secret feature“:
https://github.com/pytest-dev/pytest/issues/12707
--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:2>

Django

unread,
Jan 2, 2025, 12:07:37 PMJan 2
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted

Comment:

Thank you Adam! After some investigation following your links, I think
this makes sense. I haven't checked myself yet, but do you think there is
a sensible test to add to ensure we don't regress in this code? Also, a
nitpick, the commit message should "Refs #34900" (same with the other
Python 3.13 related ticket).
--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:3>

Django

unread,
Jan 2, 2025, 6:28:51 PMJan 2
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Johnson):

I haven't checked myself yet, but do you think there is a sensible test to
add to ensure we don't regress in this code?

We don’t seem to have any test coverage of the --pdb option right now, so
it’s not super easy to add. Even if we did, I don’t think we can easily do
it without mocking pdb, which wouldn't cover the change here.

Also, a nitpick, the commit message should "Refs #34900" (same with the
other Python 3.13 related ticket).

Should it? This is to take advantage of a new feature, not to fix
something for the new version. Similarly, my other ticket is a bug that
existed before 3.13, just got better exposed by it.
--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:4>

Django

unread,
Jan 3, 2025, 10:23:56 AMJan 3
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:5>

Django

unread,
Jan 3, 2025, 10:30:50 PMJan 3
to django-...@googlegroups.com
#36057: Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: New feature | Status: closed
Component: Testing framework | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"51df0dff3c4f28016185a9e876ee5b3420712f99" 51df0dff]:
{{{#!CommitTicketReference repository=""
revision="51df0dff3c4f28016185a9e876ee5b3420712f99"
Fixed #36057 -- Enabled test runner to debug chained exceptions with
`--pdb` on Python 3.13+.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36057#comment:6>
Reply all
Reply to author
Forward
0 new messages