d
Topic
Posts:
63
about 1 month ago

Article featured image is removed when I update article title and body_html with API

My app is working for SEO. I was trying to update article title and body_html with Python API. It was successful but the article featured image was gone. The featured image can't be found in the blog post. My code didn't change featured image at all. 

Why is it happening? How can I fix it?

i
Replies
Josh Wheeler Shopify Employee
Posts:
533
about 1 month ago

Hey there, 

This sounds strange, I haven't been able to replicate on my own test store. 

Do you happen to have an example request ID where this happened, or even the ID of the article that you were updating and a rough timeframe in which the update would have occurred? I could check our logs here to see if anything looks out of place.

Posts:
63
24 days ago

Article I'd should be 29590913101. The title is "WAS HAT TAPKEY MIT COWORKING ZU TUN?"

Posts:
63
24 days ago

I used this line target = shopify.Article.find(target_id, blog_id = blog_id) to find out the blog article. I tried to update title and description with

target.title = title
target.body_html = description

However, after I called target.save(), the feature image was removed. the image attribute of the article was gone. 

Posts:
63
24 days ago

Can you help me have a check? Thanks in advance

Josh Wheeler Shopify Employee
Posts:
533
20 days ago

Hey again, 

It looks like that article has had several updates performed on it, and I've been trying to copy them but still haven't been able to get the image to remove itself while making calls with an HTTP client. 

Is there any chance you track request IDs and know of a specific request that caused the image to be deleted, or should I assuming that all of these updates caused the image issue to occur?

Posts:
63
20 days ago

Yes, I've added some codes to check which part caused the crash. 

shopify.ShopifyResource.activate_session(session)

    result = checkAjaxPOST(request)
    if result != 1:
        return result

    type_value = request.POST.get('type')
    target_id = request.POST.get('id')
    target = ''

    if type_value == 'product':
        target = shopify.Product.find(target_id)
    elif type_value == 'article':
        blog_id = request.POST.get('blog_id')
        target = shopify.Article.find(target_id, blog_id = blog_id)
        # logger.info("article = " + target.title + " handle = " + target.handle)
        print "article = " + target.title + "; handle = " + target.handle
        if hasattr(target, 'image'):
            print "; image 0 = " + target.image.src
        else:
            print "image 0 = none"
        # target.image = target.image # image is lost after setting the focus keyword. This line is to fix this bug
    else:
        return JsonResponse({ 'error': 'not valid type_value.' })

    title = request.POST.get('title')
    keywords = request.POST.get('keywords')
    description = request.POST.get('description')
    target.title = title
    target.body_html = description
    target.save()

    target = shopify.Article.find(target_id, blog_id = blog_id)
    if hasattr(target, 'image'):
        print "; image 1 = " + target.image.src
    else:
        print "image 1 = none"

    loop_var = { 0 : {'key': 'keywords_tag', 'value': keywords} }
    for index in loop_var:
        updateMetafield(index, loop_var, target_id, type_value)

    target = shopify.Article.find(target_id, blog_id = blog_id)
    if hasattr(target, 'image'):
        print "; image 2 = " + target.image.src
    else:
        print "image 2 = none"

    data = {"title": title, "keywords": keywords, "description": description}
    return JsonResponse(data)

After testing, I got 

article = WAS HAT TAPKEY MIT COWORKING ZU TUN?; handle = was-hat-tapkey-mit-coworking-zu-tun
[Thu Oct 25 17:04:59.128389 2018] [:error] [pid 23977] ; image 0 = https://cdn.shopify.com/s/files/1/1498/3202/articles/23102018_Challenges_Coworking_900x_18bbcf15-1bec-437c-8589-012157356b86.jpg?v=1540458272
[Thu Oct 25 17:05:01.776095 2018] [:error] [pid 23977] image 1 = none
[Thu Oct 25 17:05:05.006657 2018] [:error] [pid 23977] image 2 = none

When I tried to move target.save() at the end before return, I got: 

article = WAS HAT TAPKEY MIT COWORKING ZU TUN?; handle = was-hat-tapkey-mit-coworking-zu-tun
[Thu Oct 25 17:17:45.951124 2018] [:error] [pid 24141] ; image 0 = https://cdn.shopify.com/s/files/1/1498/3202/articles/pexels-photo-884977.jpeg?v=1540459039
[Thu Oct 25 17:17:47.014086 2018] [:error] [pid 24141] ; image 1 = https://cdn.shopify.com/s/files/1/1498/3202/articles/pexels-photo-884977.jpeg?v=1540459039
[Thu Oct 25 17:17:50.308937 2018] [:error] [pid 24141] ; image 2 = https://cdn.shopify.com/s/files/1/1498/3202/articles/pexels-photo-884977.jpeg?v=1540459039

So I don't know why it's going wrong.

 

 

Posts:
63
15 days ago

Hey Josh, can you check anything in your side?

Josh Wheeler Shopify Employee
Posts:
533
5 days ago

Hello again, 

I'm still working on attempting to replicate this but have not been able to. When checking our logs as well, any logs of attempts by your app to update the blog article have now expired so I wouldn't be able to copy them. 

Would you be able to update the article with another featured image, and then perform the same update that caused the image to be removed? It would be ideal if you could only perform a single update as well to make it easier to track down where the issue may lie - or provide the value of the X-Request-Id header from the response you receive after performing the update. 

Posts:
63
4 days ago

Hi,

I tried to duplicate the issue with 4 - 5 requests for this article: https://sillycube-test.myshopify.com/blogs/news/was-hat-tapkey-mit-coworking-zu-tun. The last request can duplicate the issue.

When I tried to update the keywords metafield from "coworking" to "coworking1", the featured image was cleared. I was testing the issue in spo_development app: https://partners.shopify.com/491836/apps/1501395#/ 

Josh Wheeler Shopify Employee
Posts:
533
4 days ago

Hey again, 

Updating a metafield shouldn't ever remove a featured image either. If your last article update can replicate the issue that you've been seeing though, your last update also contained an image URL that doesn't exist - so it likely would have given the appearance of an image disappearing because our attempt to download the image returned a 404 error.

I would suggest double-checking any image URLs that you're using, and then try an update again. 

Posts:
63
Last edited 2 days ago

Thanks.

I tried to investigate where I updated the image url but didn't see it. The above code should be showing the same as my code. 

So I tried to duplicate the issue again. When I uploaded this image (the file name is called "LAUNCHING A STARTUP IN 24 HOURS.png". I tried with another file with no space. Still the same), the file url is https://cdn.shopify.com/s/files/1/1498/3202/articles/LAUNCHING_A_STARTUP_IN_24_HOURS_grande.png?v=1542360862

Again I changed the metafield to reproduce this issue. The feature image file url still exists. However, I can't find the feature image in the blog article section: https://sillycube-test.myshopify.com/admin/blogs/80952777/articles/29590913101 

I don't think I've changed the feature image in the above code. 

Also, the error is coming out at a random interval when updating the metafield (called focus keyword in my app). Sometimes it occurs. Sometimes it doesn't.