Why would a product variant not have a product ID?

Solved
Travis_D
Shopify Partner
40 1 7

We have a merchant with a large number of product variants that do not have a product_id.

 

How does this happen?

 

{'inventory_policy': 'deny', 'fulfillment_service': 'manual', 'id': 12162215575646, 'option2': 'PUMA BLACK', 'inventory_quantity': 0, 'weight_unit': 'lb', 'inventory_item_id': 12227993796702, 'price': '60.00', 'barcode': None, 'taxable': True, 'title': '3XL / PUMA BLACK', 'admin_graphql_api_id': 'gid://shopify/ProductVariant/12162215575646', 'weight': 0.0, 'position': 6, 'created_at': '2018-06-07T19:31:02-07:00', 'old_inventory_quantity': 0, 'image_id': None, 'option3': None, 'option1': '3XL', 'sku': '572366-01-3XL', 'updated_at': '2019-01-03T17:15:41-08:00', 'inventory_management': 'shopify', 'compare_at_price': '100.00', 'requires_shipping': True, 'grams': 0} 

 

 

 

 

 

Accepted Solution (1)

Accepted Solutions
hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 104 182

This is an accepted solution.

Hi @Travis_D ,

 

Thank you for your patience here. From my investigation into this, this issue appears to be isolated to the Shopify Python API library only. When I try to recreate this issue for the Shopify store involved using the REST Admin API directly, I do not see this issue:

`GET https://m*****.myshopify.com/admin/api/2020-01/variants.json?fields=id%2Cproduct_id&limit=1` returns this:

20-05-rumcc-w371d

And `GET https://m*****.myshopify.com/admin/api/2020-01/variants.json?limit=1&fields=id%2Cproduct_id&page_info=eyJsYXN0X2lkIjoyOTU0NjQ5OTQ3MywibGFzdF92YWx1ZSI6IjI5NTQ2NDk5NDczIiwiZGlyZWN0aW9uIjoibmV4dCJ9`returns this:

20-05-dt26m-7zmor

In both cases we get the "product_id"

However when running your code with the Shopify Python API library, I can verify that I can reproduce your issue. I can also reproduce this issue with this library with my own personal test store. This leads me to believe the error resides somewhere in this library. As a hunch, it may be due to the fact that the Variant class in this library tries to get the product_id value from the URL prefix: https://github.com/Shopify/shopify_python_api/blob/master/shopify/resources/variant.py. In any case, I believe you should log an issue for this in the Shopify Python API GitHub repository: https://github.com/Shopify/shopify_python_api/issues

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

View solution in original post

Replies 8 (8)
ashukasma
Shopify Partner
47 11 14

Hey @Travis_D,

 

What are using for call, GraphQL or REST?

 

It looks like you are using GraphQL because it is missing several fields from json data.

 

Shopify Expert - https://experts.shopify.com/lucentinnovation
Travis_D
Shopify Partner
40 1 7

We are using the Python SDK. 

 

variants = shopify.Variant.find(limit=250)

I've never seen this before. Most of this shop's variants have the product_id field, but there are several that do not. 

Travis_D
Shopify Partner
40 1 7

This is a legit pagination bug by Shopify. 

 

In follow up calls to shopify.Variant.find when the from_ URL is passed, product_id is not returned, even if it's specified in the fields paramter. 

 

Ex:

 

 

next_url = None
while True:
    if next_url:
        shopify_variants = shopify.Variant.find(from_=next_url)
    else:
        shopify_variants = shopify.Variant.find(limit=1, fields='id,product_id',)

    for shopify_variant in shopify_variants:
        print('{},{}'.format(next_url, shopify_variant.to_dict()))

    if next_url:
        # show only the second page
        break

    if shopify_variants.has_next_page():
        next_url = shopify_variants.next_page_url
    else:
        break

 

 

outputs:

 

 

None,{'id': 29546499473, 'product_id': 8595877265}
https://$shop/admin/api/2020-01/variants.json?limit=1&fields=id%2Cproduct_id&page_info=$pageinfo,{'id': 29546499537}

 

X-Request-ID: d3a372b1-6b1c-4273-9833-80aa2eab0490 (first call)

X-Request-ID: 1e15c52e-432f-4dbc-b53a-f4c6efe6f8c4 (second call)

 

It seems like a server side issue and not a Python SDK issue. We are using API version 2020-01 and SDK version #7.0.1. 

 

 

Travis_D
Shopify Partner
40 1 7

Of course, the work around for this:

 

        try:
            product_id = shopify_variant.product_id
        except AttributeError as e:
            shopify_variant = shopify.Variant.find(shopify_variant.id)

Results in:

 

Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service.

 

Lol!

 

 

hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 104 182

Hi @Travis_D ,

 

This seems like a very peculiar issue. Could you share with me the myshopify.com URL of the store experiencing this issue, and the Product Variant IDs that have this problem? Feel free to DM me this information if you are not comfortable with sharing it on this thread

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 104 182

This is an accepted solution.

Hi @Travis_D ,

 

Thank you for your patience here. From my investigation into this, this issue appears to be isolated to the Shopify Python API library only. When I try to recreate this issue for the Shopify store involved using the REST Admin API directly, I do not see this issue:

`GET https://m*****.myshopify.com/admin/api/2020-01/variants.json?fields=id%2Cproduct_id&limit=1` returns this:

20-05-rumcc-w371d

And `GET https://m*****.myshopify.com/admin/api/2020-01/variants.json?limit=1&fields=id%2Cproduct_id&page_info=eyJsYXN0X2lkIjoyOTU0NjQ5OTQ3MywibGFzdF92YWx1ZSI6IjI5NTQ2NDk5NDczIiwiZGlyZWN0aW9uIjoibmV4dCJ9`returns this:

20-05-dt26m-7zmor

In both cases we get the "product_id"

However when running your code with the Shopify Python API library, I can verify that I can reproduce your issue. I can also reproduce this issue with this library with my own personal test store. This leads me to believe the error resides somewhere in this library. As a hunch, it may be due to the fact that the Variant class in this library tries to get the product_id value from the URL prefix: https://github.com/Shopify/shopify_python_api/blob/master/shopify/resources/variant.py. In any case, I believe you should log an issue for this in the Shopify Python API GitHub repository: https://github.com/Shopify/shopify_python_api/issues

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Travis_D
Shopify Partner
40 1 7

Sounds good. I will do that. 

 

Thanks looking into this thoroughly!

 

Travis_D
Shopify Partner
40 1 7

FYI

 

Issue posted here