Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Note: For changes to the API, see https://shopify.dev/changelog?filter=api
## Unreleased
- Preserve in-place changes to nested REST attributes when saving resources.

## 16.3.0 (2026-08-04)
- [#1443](https://github.com/Shopify/shopify-api-ruby/pull/1443) Add `ShopifyAPI::Utils::ShopValidator` with `sanitize_shop_domain` and `sanitize!`.
Expand Down
2 changes: 2 additions & 0 deletions lib/shopify_api/rest/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "active_support/inflector"
require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/object/deep_dup"

module ShopifyAPI
module Rest
Expand Down Expand Up @@ -301,6 +302,7 @@ def create_instance(data:, session:, instance: nil)
end
end

instance.original_state = instance.original_state.deep_dup
instance
end
end
Expand Down
22 changes: 22 additions & 0 deletions test/clients/base_rest_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ def test_saves_removing_children
assert_requested(stubbed_request)
end

def test_saves_in_place_mutations_to_nested_attributes
resource = TestHelpers::FakeResource.create_instance(
session: @session,
data: {
"id" => 1,
"details" => { "address" => { "first_name" => "John" }, "tags" => ["original"] },
},
)
stubbed_request = stub_request(:put, "#{@prefix}/fake_resources/1.json")
.with(body: hash_including(
"fake_resource" => hash_including(
"details" => { "address" => { "first_name" => "Jane" } },
),
))
.to_return(status: 200)

resource.details["address"]["first_name"] = "Jane"
resource.save

assert_requested(stubbed_request)
end

def test_loads_unknown_attribute_with_special_character
body = { fake_resource: { id: 1, attribute: "attribute", "unknown?": "some-value" } }.to_json

Expand Down
Loading