Skip to content

fix: Network.id now returns libpod lowercase 'id', add get_compatible… - #660

Open
VincentSamuelPaul wants to merge 1 commit into
containers:mainfrom
VincentSamuelPaul:fix/network-id-bug
Open

VincentSamuelPaul wants to merge 1 commit into
containers:mainfrom
VincentSamuelPaul:fix/network-id-bug

Conversation

@VincentSamuelPaul

Copy link
Copy Markdown

Fixes #584

Network.id was looking for self.attrs["Id"] (uppercase), but Podman's
libpod API returns "id" (lowercase), causing it to always fall back to a
synthetic hash-based ID. Passing that fake ID to networks.get() would then fail.

Changes:
Network.id now correctly reads attrs["id"] (libpod format)
Added Network.get_compatible_id() for Docker-compatible endpoints that use attrs["Id"]
Network.connect() uses get_compatible_id() since it goes through the Docker-compatible endpoint
Updated test_id to use libpod format, added test_compatible_id

This follows the approach suggested by @inknos in #587, analogous to how
Network.name already handles both "Name" and "name".

Copilot AI lite review requested due to automatic review settings September 25, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Restore the uppercase Id fallback and address the requested test coverage and lint issue.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Updates network ID handling for libpod’s lowercase id format while preserving Docker-compatible IDs for connect().

Changes:

  • Uses lowercase id for Network.id.
  • Adds get_compatible_id() for compatible endpoints.
  • Updates connection handling and unit tests.

The uppercase Id fallback remains necessary for compatible network responses. Additional lowercase-ID coverage and trailing-whitespace cleanup are also required.

File Description
podman/​tests/​unit/​test_network.py Updates network ID tests and adds compatibility coverage.
podman/​domain/​networks.py Implements libpod and compatible network ID handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread podman/domain/networks.py
"""str: Returns the identifier of the network."""
with suppress(KeyError):
return self.attrs["Id"]
return self.attrs["id"]
@VincentSamuelPaul

Copy link
Copy Markdown
Author

The testing-farm:*:distro-fedora-all and testing-farm:fedora-44-x86_64:distro-sanity failures appear to be infrastructure errors unrelated to this change — they error out immediately with "1 plan errored out" and no test output, which is the same pattern seen in other recent PRs. No source logic was modified that would affect distro packaging or sanity checks.

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have some comments. Please also add in to commit Fixes: #NUMBER_OF_ISSUE. Thanks!

Comment thread podman/domain/networks.py Outdated
"""str: Returns the identifier of the network (Docker-compatible format)."""
with suppress(KeyError):
return self.attrs["Id"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove these white spaces?

Suggested change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it, removed trailing whitespace.

Comment thread podman/domain/networks.py Outdated

return None

def get_compatible_id(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be private function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it private (_get_compatible_id)

Fixes: containers#584

Network.id was looking for self.attrs["Id"] (uppercase), but Podman's
libpod API returns "id" (lowercase), causing it to always fall back to a
synthetic hash-based ID.

Changes:
- Network.id now checks attrs["id"] first, then attrs["Id"] as fallback
- Added private Network._get_compatible_id() for Docker-compatible endpoints
- Network.connect() uses _get_compatible_id() for the NetworkID field
- Updated test_id to cover both formats, added test_compatible_id

Follows the approach suggested by @inknos in containers#587, analogous to how
Network.name handles both "Name" and "name".

Signed-off-by: Vincent Samuel Paul <vincentsamuelpaul@gmail.com>
@VincentSamuelPaul

Copy link
Copy Markdown
Author

Hi @Honny1, I've addressed all the review comments — removed trailing whitespace, made the function private (_get_compatible_id), and added Fixes: #584 to the commit. Let me know if there's anything else needed. Thanks!

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@VincentSamuelPaul

Copy link
Copy Markdown
Author

Thanks for the review!

This branch was successfully deployed

1 active deployment
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.

[BUG] Getting a network by ID does not work

3 participants