Skip to content

TPT-4428: Change assignments type from dict to list in ip_addresses_assign#687

Open
mawilk90 wants to merge 1 commit intolinode:devfrom
mawilk90:hotfix/TPT-4428-linodepy-incorrect-type-of-ip-address-assignments
Open

TPT-4428: Change assignments type from dict to list in ip_addresses_assign#687
mawilk90 wants to merge 1 commit intolinode:devfrom
mawilk90:hotfix/TPT-4428-linodepy-incorrect-type-of-ip-address-assignments

Conversation

@mawilk90
Copy link
Copy Markdown
Contributor

@mawilk90 mawilk90 commented Apr 23, 2026

📝 Description

Current type of "assignments" passed into "ip_addresses_assign" method is dict what causes an API error during IP assignment as it requires array/list.

https://techdocs.akamai.com/linode-api/reference/post-assign-ips

✔️ How to Test

make test-unit

@mawilk90 mawilk90 requested review from a team as code owners April 23, 2026 12:19
@mawilk90 mawilk90 requested review from psnoch-akamai and yec-akamai and removed request for a team, psnoch-akamai and yec-akamai April 23, 2026 12:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the NetworkingGroup.ip_addresses_assign API to send assignments as an array/list (matching the Linode API contract) instead of a dict wrapper, and aligns unit tests accordingly.

Changes:

  • Update ip_addresses_assign to iterate over and submit a list of assignment objects.
  • Update unit test to pass and assert list-shaped assignments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
linode_api4/groups/networking.py Adjusts ip_addresses_assign to accept and POST list assignments.
test/unit/linode_client_test.py Updates test to use list assignments and validate request payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot AI Apr 23, 2026

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.
Comment on lines 452 to 454
:param assignments: Any number of assignments to make. See
:any:`IPAddress.to` for details on how to construct
assignments.
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The docstring still says "Any number of assignments to make" but the method now takes a single list of assignment objects. Please update the wording to reflect the actual expected argument shape to avoid confusing API consumers.

Suggested change
:param assignments: Any number of assignments to make. See
:any:`IPAddress.to` for details on how to construct
assignments.
:param assignments: A list of assignment objects to make. See
:any:`IPAddress.to` for details on how to construct
each assignment.

Copilot uses AI. Check for mistakes.
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.

2 participants