Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.
This repository was archived by the owner on Oct 6, 2026. It is now read-only.

AttributeError: product - when I want to create and save a Product #404

Closed

Description

@jerkkao

I found an issue when I want to do some basic Product creation which is from the sample code.
I think it's caused by the code in /resources/product.py, line 39 when it checks there is any variant in the product or not.
if 'variants' in self.product.attributes:

With Python 3.7.5

def main():
  # with the right API_KEY, PASSWORD, SHOP_NAME, API_VERSION
  shop_url = "https://%s:%s@%s.myshopify.com/admin/api/%s" % (API_KEY, PASSWORD, SHOP_NAME, API_VERSION)
  shopify.ShopifyResource.set_site(shop_url)

  product = shopify.Product()
  product.title = "Shopify test title"
  saved_successfully = product.save()

if __name__ == '__main__':
  main()

Output with call stack

Traceback (most recent call last):
  File "main.py", line 51, in <module>
    main()
  File "main.py", line 42, in main
    saved_successfully = product.save()
  File "/usr/local/lib/python3.7/site-packages/shopify/resources/product.py", line 39, in save
    if 'variants' in self.product.attributes:
  File "/usr/local/lib/python3.7/site-packages/pyactiveresource/activeresource.py", line 917, in __getattr__
    raise AttributeError(name)
AttributeError: product

Thanks,

Activity

  1. smubbs commented on Aug 11, 2020

    @smubbs
    Contributor

    #386 Similar issue here

  2. asfakianos commented on Aug 13, 2020

    @asfakianos
    Contributor

    I fixed this and submitted a pull request (#403). If you want to fix it manually, you can change if 'variants' in self.product.attributes: to if 'variants' in self.attributes: in shopify/resources/product.py.

    EDIT: It appears this was already mentioned in #386 and may have caused some other issues, though I have yet to personally experience any.

  3. thecodepixi commented on May 20, 2021

    @thecodepixi

    This appears to have been resolved by a previous PR. Closing as stale. If the issue persists, please feel free to open a new issue on the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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