Last active
June 21, 2022 13:06
-
-
Save marisveide/075cc57d9861c4b7c6c585236f80d78e to your computer and use it in GitHub Desktop.
Just run that to see the bug being replicated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'shopify_api' | |
shop = ShopifyAPI::Session.new('ultraexportimport.myshopify.com', '****************************') | |
ShopifyAPI::Base.activate_session(shop) | |
begin | |
######################################################## | |
# 1 - Create new Collection | |
######################################################## | |
data = { | |
"custom_collection": { | |
"handle": "custom-collection-#{rand(1000)}", | |
"title": "Custom Collection", | |
"image": {"src": "http://cdn3-www.cattime.com/assets/uploads/2011/08/best-kitten-names-1.jpg" | |
} | |
} | |
} | |
entity = ShopifyAPI::CustomCollection.new(data) | |
result = entity.save | |
if result | |
puts "Created:" | |
puts JSON.pretty_generate(JSON.parse(entity.to_json)) | |
else | |
if entity.errors | |
puts | |
puts "Errors:" | |
puts JSON.pretty_generate(JSON.parse(entity.errors.to_json)) | |
else | |
puts | |
puts "Don't know what happened - didnt't save, but there are also no errors..." | |
end | |
abort | |
end | |
puts | |
puts "========================================" | |
puts "Check that image link from loaded Collection - it works!" | |
puts "After you will load and simply save the same entity, it will not work anymore, and image will be lost, and entity saving will fail." | |
puts "Press Enter to see what happens after save..." | |
gets | |
id = entity.id | |
######################################################## | |
# 2 - Load that same Collection by ID from Shopify | |
######################################################## | |
puts | |
puts "========================================" | |
puts "Searching by ID: #{id}" | |
entity = ShopifyAPI::CustomCollection.find(id) | |
puts | |
puts "========================================" | |
puts "Loaded:" | |
puts JSON.pretty_generate(JSON.parse(entity.to_json)) | |
sleep 1 # Especially, when sleeping here, the issue repeats more often | |
puts "========================================" | |
puts "Saving without any changes..." | |
result = entity.save | |
if result | |
puts "Saved:" | |
puts JSON.pretty_generate(JSON.parse(entity.to_json)) | |
puts | |
puts "OK, it saved this time - but please, repeat the same script several times, and quite often it will fail saving." | |
else | |
if entity.errors | |
puts | |
puts "Errors:" | |
puts JSON.pretty_generate(JSON.parse(entity.errors.to_json)) | |
else | |
puts | |
puts "Don't know what happened - didnt't save, but there are also no errors..." | |
end | |
abort | |
end | |
rescue => e | |
puts | |
puts "Error:" | |
puts e | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment