Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions linode_api4/groups/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ def ip_addresses_assign(self, assignments, region):
:param assignments: Any number of assignments to make. See
:any:`IPAddress.to` for details on how to construct
assignments.
Comment thread
mawilk90 marked this conversation as resolved.
:type assignments: dct
:type assignments: list
"""

for a in assignments["assignments"]:
for a in assignments:
if not "address" in a or not "linode_id" in a:
Comment on lines +458 to 459

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

Changing ip_addresses_assign to accept a bare list is a breaking change for any callers that were previously passing {"assignments": [...]}. Consider supporting both shapes for backward compatibility (e.g., if assignments is a dict with an assignments key, unwrap it) or at least raise a clearer error when a dict is provided (current loop will iterate dict keys and raise a generic Invalid assignment).

Suggested change
for a in assignments:
if not "address" in a or not "linode_id" in a:
if isinstance(assignments, dict):
if "assignments" in assignments:
assignments = assignments["assignments"]
else:
raise ValueError(
"Invalid assignments payload: expected a list of assignments "
"or a dict containing an 'assignments' key, got {}".format(
assignments
)
)
if not isinstance(assignments, list):
raise ValueError(
"Invalid assignments payload: expected a list of assignments, got {}".format(
type(assignments).__name__
)
)
for a in assignments:
if not isinstance(a, dict) or "address" not in a or "linode_id" not in a:

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it really a breaking change in this context?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Copilot comment is a false positive. The function signature is consistent with the deprecated predecessor and there are no existing callers of ip_addresses_assign to break.

raise ValueError("Invalid assignment: {}".format(a))

Expand Down
4 changes: 2 additions & 2 deletions test/unit/linode_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,13 +1407,13 @@ def test_ip_addresses_assign(self):

with self.mock_post({}) as m:
self.client.networking.ip_addresses_assign(
{"assignments": [{"address": "192.0.2.1", "linode_id": 123}]},
[{"address": "192.0.2.1", "linode_id": 123}],
"us-east",
)
self.assertEqual(m.call_url, "/networking/ips/assign")
self.assertEqual(
m.call_data["assignments"],
{"assignments": [{"address": "192.0.2.1", "linode_id": 123}]},
[{"address": "192.0.2.1", "linode_id": 123}],
)
self.assertEqual(m.call_data["region"], "us-east")

Expand Down
Loading