From 4b94e8f06efdd7e4e35d313bc0e598358602b7f4 Mon Sep 17 00:00:00 2001 From: Hamid Khateb Date: Fri, 22 Aug 2025 09:08:12 +0100 Subject: [PATCH] Fix NetworkManagerSettings.get_connections_by_id not using the bus it was initialized with The get_connections_by_id does not work properly with explicitly passed bus, and raises the following exception: settings_paths = await nm_settings.get_connections_by_id("eth0") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../networkmanager/objects.py", line 177, in get_connections_by_id settings_properties = await settings.get_settings() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../dbus_proxy_async_method.py", line 108, in _dbus_async_call reply_message = await bus.call_async(call_message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sdbus.dbus_exceptions.DbusServiceUnknownError: The name org.freedesktop.NetworkManager was not provided by any .service files This exception was discovered with the following test code: import asyncio from sdbus import sd_bus_open_system from sdbus_async.networkmanager import NetworkManagerSettings async def test_get_connections_by_id(): system_bus = sd_bus_open_system() nm_settings = NetworkManagerSettings(system_bus) settings_paths = await nm_settings.get_connections_by_id("eth0") print(settings_paths) if __name__ == "__main__": asyncio.run(test_get_connections_by_id()) After this fix, the issue is resolved and get_connections_by_id works correctly without raising an exception. --- sdbus_async/networkmanager/objects.py | 3 ++- sdbus_block/networkmanager/objects.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sdbus_async/networkmanager/objects.py b/sdbus_async/networkmanager/objects.py index e03c69a..f5ae24e 100644 --- a/sdbus_async/networkmanager/objects.py +++ b/sdbus_async/networkmanager/objects.py @@ -159,6 +159,7 @@ def __init__(self, bus: Optional[SdBus] = None) -> None: NETWORK_MANAGER_SERVICE_NAME, '/org/freedesktop/NetworkManager/Settings', bus) + self._nm_used_bus = bus async def get_connections_by_id(self, connection_id: str) -> List[str]: """Helper method to get a list of connection profile paths @@ -171,7 +172,7 @@ async def get_connections_by_id(self, connection_id: str) -> List[str]: connection_paths_with_matching_id = [] connection_paths: List[str] = await self.connections for connection_path in connection_paths: - settings = NetworkConnectionSettings(connection_path) + settings = NetworkConnectionSettings(connection_path, self._nm_used_bus) settings_properites = await settings.get_settings() # settings_properites["connection"]["id"][1] gives the id value: if settings_properites["connection"]["id"][1] == connection_id: diff --git a/sdbus_block/networkmanager/objects.py b/sdbus_block/networkmanager/objects.py index 3d4c68d..ef48e29 100644 --- a/sdbus_block/networkmanager/objects.py +++ b/sdbus_block/networkmanager/objects.py @@ -154,6 +154,7 @@ def __init__(self, bus: Optional[SdBus] = None) -> None: NETWORK_MANAGER_SERVICE_NAME, '/org/freedesktop/NetworkManager/Settings', bus) + self._nm_used_bus = bus def get_connections_by_id(self, connection_id: str) -> List[str]: """Helper method to get a list of connection profile paths @@ -165,7 +166,7 @@ def get_connections_by_id(self, connection_id: str) -> List[str]: """ connection_paths_with_matching_id = [] for connection_path in self.connections: - profile = NetworkConnectionSettings(connection_path) + profile = NetworkConnectionSettings(connection_path, self._nm_used_bus) # profile.get_settings()["connection"]["id"][1] gives the id value: if profile.get_settings()["connection"]["id"][1] == connection_id: connection_paths_with_matching_id.append(connection_path)