[Pkg-utopia-maintainers] Bug#1144533: dbus-python: Unimportable module when building in Python 3.15

Maximiliano Curia maxy at gnuservers.com.ar
Sun Aug 16 17:39:19 BST 2026


¡Hola Simon!

El 2026-08-16 a las 15:14 +0100, Simon McVittie escribió:
>Control: forwarded -1 https://gitlab.freedesktop.org/dbus/dbus-python/-/work_items/59

I've been getting 504 Gateway Time-out errors from
gitlab.freedesktop.org, I could not clone the repository nor access
upsteam issue tracker.

Update, while checking the code the page finally could be loaded, it
would have been very useful to be able the access this issue prior
patching the code. :)

I'll try to send a version of this conversation upstream, if I manage to
create a user in the gitlab instance before another 504.


>On Sun, 16 Aug 2026 at 15:25:57 +0200, Maximiliano Curia wrote:
>>The problem seems to be caused by the fact that the Connection is a
>>GenericAlloc that's missing the PyGC_Head header header, this is now detected in
>>Python 3.15 (see: https://github.com/python/cpython/issues/134786).
>>
>>The weakref was introduced by ebecd174 but the previous mechanism still
>>works, so I'm reverting ebecd174 and adding a regression test that
>>should fail in python 3.12 to 3.14.
>
>I'd prefer to address this upstream rather than as a Debian-specific 
>patch (see also: the forwarded report above).

>Would this revert be considered (by Python upstream) to be a correct 
>solution, or a workaround, or what? Is there a porting guide available 
>that would clarify what the most appropriate change is?

The issue with the way the weakref is handled in now detected as an
error, but it was trying to access an invalid memory before (see the
regression test, you can test it against 3.12, 3.13 or 3.14 and it
produces a segfault). The issue has to do with how the weak refs are
implemented in python, which basically uses the struct reserved for he
gc, which the connection and server objects don't have.

To have working weakrefs for connection and server, needs a bit of
tweaking of the parts.

So, the error actually says (a part of) how to solve it
'_dbus_bindings.Connection has the Py_TPFLAGS_MANAGED_WEAKREF flag but
not Py_TPFLAGS_HAVE_GC flag', that is in DBusPyConnection_Type (conn.c),
you'll need to add the flag Py_TPFLAGS_HAVE_GC:
#if DBUSPY_PY_VERSION_AT_LEAST(3, 12, 0, 0)
     Py_TPFLAGS_MANAGED_WEAKREF | Py_TPFLAGS_HAVE_GC |
#endif
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,

The same for DBusPyServer_Type.

But then you also need to write the corresponding traverse functions
(currently they are NULL) probably using Py_VISIT on the subelements
that can hold a python object, handle the GC on dealloc.

>ebecd174 was an attempt to follow what, at the time, I believed was 
>upstream best-practice. Perhaps I was wrong about that, or perhaps 
>best-practice has changed - but I'd prefer to know which is 
>applicable.

Well, I don't have as much context as you have about this project, I
think that you wanted a weakref to avoid an unclaimable reference
cycle, if that's the case, then the revert is going to bring that back.

So probably finishing the weakref patch would be a better approach (the
regression test I included in the patch should still be useful for
that).

Happy hacking,
-- 
"Get your data structures correct first, and the rest of the program will 
write itself"
-- David Jones
Saludos /\/\ /\ >< `/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-utopia-maintainers/attachments/20260816/4daed031/attachment-0001.sig>


More information about the Pkg-utopia-maintainers mailing list