Skip to content

apport_python_hook: support dbus-broker - #645

Open
bdrung wants to merge 4 commits into
canonical:mainfrom
bdrung:fix-dbus
Open

apport_python_hook: support dbus-broker#645
bdrung wants to merge 4 commits into
canonical:mainfrom
bdrung:fix-dbus

Conversation

@bdrung

@bdrung bdrung commented Aug 18, 2026

Copy link
Copy Markdown
Member

The tests test_dbus_service_unknown_wrongbus_notrunning and test_dbus_service_unknown_wrongbus_running started to fail once Ubuntu switched to dbus-broker (see https://launchpad.net/bugs/2015538).

These tests create Python code similar to:

#!/usr/bin/python3
import dbus

obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
assert obj
obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")

On Ubuntu 26.04 this code fails with:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner
    return self.get_name_owner(bus_name)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner
    return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              BUS_DAEMON_IFACE, 'GetNameOwner',
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              's', (bus_name,))
                              ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.gtk.vfs.Metadata': no such name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/test.py", line 4, in <module>
    obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object
    return self.ProxyObjectClass(self, bus_name, object_path,
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                 introspect=introspect,
                                 ^^^^^^^^^^^^^^^^^^^^^^
                                 follow_name_owner_changes=follow_name_owner_changes)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
                          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner
    self.start_service_by_name(bus_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name
    return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     BUS_DAEMON_IFACE,
                                     ^^^^^^^^^^^^^^^^^
                                     'StartServiceByName',
                                     ^^^^^^^^^^^^^^^^^^^^^
                                     'su', (bus_name, flags)))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gtk.vfs.Metadata was not provided by any .service files

On Ubuntu 26.10 with dbus-broker it fails with less information in the exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner
    return self.get_name_owner(bus_name)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner
    return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              BUS_DAEMON_IFACE, 'GetNameOwner',
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              's', (bus_name,))
                              ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: The name does not have an owner

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/test.py", line 6, in <module>
    obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object
    return self.ProxyObjectClass(self, bus_name, object_path,
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                 introspect=introspect,
                                 ^^^^^^^^^^^^^^^^^^^^^^
                                 follow_name_owner_changes=follow_name_owner_changes)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
                          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner
    self.start_service_by_name(bus_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name
    return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     BUS_DAEMON_IFACE,
                                     ^^^^^^^^^^^^^^^^^
                                     'StartServiceByName',
                                     ^^^^^^^^^^^^^^^^^^^^^
                                     'su', (bus_name, flags)))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable

The dbus-python code uses bus_name as variable before calling D-Bus in most cases. So walk down the traceback to extract the bus name from there.

Bug: https://launchpad.net/bugs/2163744

bdrung added 4 commits August 18, 2026 18:06
In case `dbus_service_unknown_analysis` fails to parse the D-Bus name,
the function should print an error message and return. If `sys.stderr`
is not available, no error message is printed but the function is
continued.

Return in that case as well, because the D-Bus name is required for the
following code.
The variable `service` is used for the content of the D-Bus service
files. mypy would complain when reusing this variable for `str` later
on.
Let `dbus_service_unknown_analysis` return a `dict` to avoid needing to
pass around the problem report. This allows adding type hints to this
function without needing to make `apport.report.Report` available.
The tests `test_dbus_service_unknown_wrongbus_notrunning` and
`test_dbus_service_unknown_wrongbus_running` started to fail once Ubuntu
switched to dbus-broker (see https://launchpad.net/bugs/2015538).

These tests create Python code similar to:

```python
#!/usr/bin/python3
import dbus

obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
assert obj
obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
```

On Ubuntu 26.04 this code fails with:

```
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner
    return self.get_name_owner(bus_name)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner
    return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              BUS_DAEMON_IFACE, 'GetNameOwner',
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              's', (bus_name,))
                              ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.gtk.vfs.Metadata': no such name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/test.py", line 4, in <module>
    obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object
    return self.ProxyObjectClass(self, bus_name, object_path,
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                 introspect=introspect,
                                 ^^^^^^^^^^^^^^^^^^^^^^
                                 follow_name_owner_changes=follow_name_owner_changes)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
                          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner
    self.start_service_by_name(bus_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name
    return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     BUS_DAEMON_IFACE,
                                     ^^^^^^^^^^^^^^^^^
                                     'StartServiceByName',
                                     ^^^^^^^^^^^^^^^^^^^^^
                                     'su', (bus_name, flags)))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gtk.vfs.Metadata was not provided by any .service files
```

On Ubuntu 26.10 with dbus-broker it fails with less information in the
exception:

```
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner
    return self.get_name_owner(bus_name)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner
    return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              BUS_DAEMON_IFACE, 'GetNameOwner',
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              's', (bus_name,))
                              ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: The name does not have an owner

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/test.py", line 6, in <module>
    obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata")
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object
    return self.ProxyObjectClass(self, bus_name, object_path,
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                 introspect=introspect,
                                 ^^^^^^^^^^^^^^^^^^^^^^
                                 follow_name_owner_changes=follow_name_owner_changes)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
                          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner
    self.start_service_by_name(bus_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name
    return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     BUS_DAEMON_IFACE,
                                     ^^^^^^^^^^^^^^^^^
                                     'StartServiceByName',
                                     ^^^^^^^^^^^^^^^^^^^^^
                                     'su', (bus_name, flags)))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
        message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable
```

The dbus-python code uses `bus_name` as variable before calling D-Bus in
most cases. So walk down the traceback to extract the bus name from
there.

Bug: https://launchpad.net/bugs/2163744
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.48%. Comparing base (7ce5916) to head (4343391).

Files with missing lines Patch % Lines
apport_python_hook.py 77.27% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #645      +/-   ##
==========================================
- Coverage   84.48%   84.48%   -0.01%     
==========================================
  Files         106      106              
  Lines       21044    21055      +11     
  Branches     3192     3194       +2     
==========================================
+ Hits        17780    17788       +8     
- Misses       2790     2792       +2     
- Partials      474      475       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant