From 0d88ef891638f3adf2bec6af7b54521bc8c43022 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Fri, 5 Sep 2025 22:04:00 +0000 Subject: [PATCH] network.id should look for attrs "Id" and "id"... ...before falling back to a synthetic id based on the hash of the network name. Checking both is needed to support the Docker-compatible format ("Id") and Libpod-native format ("id"). This is analagous to how podman-py handles network.name -- we check attrs "Name" and "name" in that order. Fixes #584 Signed-off-by: Nicolas Lacasse --- podman/domain/networks.py | 5 ++++- podman/tests/integration/test_networks.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/podman/domain/networks.py b/podman/domain/networks.py index ac25dad6..7fa599bc 100644 --- a/podman/domain/networks.py +++ b/podman/domain/networks.py @@ -30,9 +30,12 @@ class Network(PodmanResource): @property def id(self): # pylint: disable=invalid-name """str: Returns the identifier of the network.""" - with suppress(KeyError): + if "Id" in self.attrs: return self.attrs["Id"] + if "id" in self.attrs: + return self.attrs["id"] + with suppress(KeyError): sha256 = hashlib.sha256(self.attrs["name"].encode("ascii")) return sha256.hexdigest() diff --git a/podman/tests/integration/test_networks.py b/podman/tests/integration/test_networks.py index 76e9b854..182eaea6 100644 --- a/podman/tests/integration/test_networks.py +++ b/podman/tests/integration/test_networks.py @@ -64,6 +64,13 @@ def test_network_crud(self): names = [i.name for i in nets] self.assertIn("integration_test", names) + with self.subTest("Get by ID"): + network = self.client.networks.get("integration_test") + net_id = network.id + assert isinstance(net_id, str) + network_by_id = self.client.networks.get(net_id) + self.assertEqual(network.name, network_by_id.name) + with self.subTest("Delete network"): network = self.client.networks.get("integration_test") network.remove(force=True)