Skip to content

Useless HashDiff comparison when saving resource #1037

@kaarelss

Description

@kaarelss

Issue summary

When updating/saving any resource, there is useless HashDiff comparison. It looks like the intended logic is to not send attributes which are not changed, but all attributes are sent always, because comparison result contains duplicate attributes as symbols and as strings.

Expected behavior

original_state should return hash with same attribute types as to_hash methods result, so the HashDiff comparison works correctly.

Actual behavior

original_state return hash with keys as symbols, but to_hash return hash with keys as strings. Therefore the HashDiff comparison have both sets of attributes.

Steps to reproduce the problem

  1. Execute the code below
blog = ShopifyAPI::Blog.new(session: ShopifyAPI::Context.active_session)
blog.title = "My Blog"
blog.handle = "my-blog"
blog.save!

blog.handle = "my-blog-changed"
blog.save!

Look at the image, you can see that there are duplicate set of attributes after HashDiff comparison.
Screenshot at Oct 12 09-58-32

Logs

D, [2022-10-12T10:05:40.261857 #41270] DEBUG -- : Pool shutdown finished
D, [2022-10-12T10:05:42.024169 #41270] DEBUG -- : [httplog] Connecting: excelify-karlis-2.myshopify.com:443
D, [2022-10-12T10:05:42.570946 #41270] DEBUG -- : [httplog] Sending: POST http://excelify-karlis-2.myshopify.com:443/admin/api/2022-04/blogs.json
D, [2022-10-12T10:05:42.571025 #41270] DEBUG -- : [httplog] Data: {"blog":{"handle":"my-blog","title":"My Blog"}}
D, [2022-10-12T10:05:42.571044 #41270] DEBUG -- : [httplog] Status: 201
D, [2022-10-12T10:05:42.571062 #41270] DEBUG -- : [httplog] Benchmark: 0.508879 seconds
D, [2022-10-12T10:05:42.571085 #41270] DEBUG -- : [httplog] Response:
{"blog":{"id":79965618227,"handle":"my-blog","title":"My Blog","updated_at":"2022-10-12T10:05:42+03:00","commentable":"no","feedburner":null,"feedburner_location":null,"created_at":"2022-10-12T10:05:42+03:00","template_suffix":null,"tags":"","admin_graphql_api_id":"gid:\/\/shopify\/OnlineStoreBlog\/79965618227"}}
D, [2022-10-12T10:05:43.091768 #41270] DEBUG -- : [httplog] Connecting: excelify-karlis-2.myshopify.com:443
D, [2022-10-12T10:05:43.524617 #41270] DEBUG -- : [httplog] Sending: PUT http://excelify-karlis-2.myshopify.com:443/admin/api/2022-04/blogs/79965618227.json
D, [2022-10-12T10:05:43.524692 #41270] DEBUG -- : [httplog] Data: {"blog":{"id":79965618227,"handle":"my-blog-changed","title":"My Blog","updated_at":"2022-10-12T10:05:42+03:00","commentable":"no","feedburner":null,"feedburner_location":null,"created_at":"2022-10-12T10:05:42+03:00","template_suffix":null,"tags":"","admin_graphql_api_id":"gid://shopify/OnlineStoreBlog/79965618227"}}
D, [2022-10-12T10:05:43.524711 #41270] DEBUG -- : [httplog] Status: 200
D, [2022-10-12T10:05:43.524729 #41270] DEBUG -- : [httplog] Benchmark: 0.413646 seconds
D, [2022-10-12T10:05:43.524760 #41270] DEBUG -- : [httplog] Response:
{"blog":{"title":"My Blog","handle":"my-blog-changed","commentable":"no","feedburner":null,"feedburner_location":null,"template_suffix":null,"id":79965618227,"updated_at":"2022-10-12T10:05:43+03:00","created_at":"2022-10-12T10:05:42+03:00","tags":"","admin_graphql_api_id":"gid:\/\/shopify\/OnlineStoreBlog\/79965618227"}}

Specifications

  • shopify_api version: 12.0.0
  • Shopify API version used (example: 2022-04):

@itissible/matrixify

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions