Skip to content

Conversation

@lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Apr 23, 2025

📝 Description

This pull request implements a new put_class JSONObject ClassVar, which allows JSONObject classes to specify an alternate JSONObject class to use as the schema when serializing for PUT requests.

This prevents read-only fields under mutable substructs from being included in PUT request bodies.

✔️ How to Test

The following changes expected you have pulled down this PR locally and run make install.

Unit Testing

make test-unit

Manual Testing

  1. In a linode_api4-python sandbox environment (e.g. dx-devenv), run the following:
from dataclasses import dataclass
from typing import Optional
from linode_api4 import JSONObject


@dataclass
class SubStructOptions(JSONObject):
    test1: Optional[str] = None


@dataclass
class SubStruct(JSONObject):
    put_class = SubStructOptions

    test1: str = ""
    test2: int = 0


substruct_value = SubStruct(test1="abc", test2=123)

print("is_put=False:", substruct_value._serialize())
print("is_put=True:", substruct_value._serialize(is_put=True))
  1. Ensure the output matches the following:
is_put=False: {'test1': 'abc', 'test2': 123}
is_put=True: {'test1': 'abc'}

@lgarber-akamai lgarber-akamai added new-feature for new features in the changelog. improvement for improvements in existing functionality in the changelog. and removed new-feature for new features in the changelog. labels Apr 23, 2025
@lgarber-akamai lgarber-akamai marked this pull request as ready for review April 23, 2025 20:36
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner April 23, 2025 20:36
@lgarber-akamai lgarber-akamai requested review from ezilber-akamai, yec-akamai and zliang-akamai and removed request for a team and ezilber-akamai April 23, 2025 20:36
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

Tested and works well on my end, nice work!

Copy link
Contributor

@ykim-akamai ykim-akamai left a comment

Choose a reason for hiding this comment

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

LGTM

@lgarber-akamai lgarber-akamai merged commit b2eff93 into linode:dev Apr 28, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement for improvements in existing functionality in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants