You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of our data pipeline, there is a step where we update the metafields of an order to include custom business information. This logic was implemented successfully and had been functioning correctly for some time.
However, starting approximately one month ago, the code began to fail sometimes with the following error:
File "/usr/src/app/data_pipelines/assets/shopify/utils.py", line 221, in add_healthie_id_order
return order.add_metafield(metafield)
File "/usr/local/lib/python3.10/site-packages/shopify/mixins.py", line 28, in add_metafield
metafield.save()
File "/usr/local/lib/python3.10/site-packages/pyactiveresource/activeresource.py", line 831, in save
response = self.klass.connection.put(
File "/usr/local/lib/python3.10/site-packages/pyactiveresource/connection.py", line 363, in put
return self._open('PUT', path, headers=headers, data=data)
File "/usr/local/lib/python3.10/site-packages/shopify/base.py", line 23, in _open
self.response = super(ShopifyConnection, self)._open(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/pyactiveresource/connection.py", line 290, in _open
raise Error(err, url)
My code looks like this:
shopify.ShopifyResource.set_site(get_shop_url())
METAFIELD_CONFIG= {
"namespace": "custom",
"key": "other_id",
"type": "single_line_text_field",
"value": None,
}
defget_metafield(shopify_resource: shopify.ShopifyResource, metafield_config: dict[str, Any]) ->shopify.Metafield:
""" Retrieve a metafield from a Shopify resource or create a new one if not found. Args: shopify_resource (shopify.ShopifyResource): The Shopify resource to retrieve the metafield from. metafield_config (Dict[str, Any]): The configuration of the metafield to create if not found. Returns: shopify.Metafield: The retrieved or newly created metafield. """ifnotisinstance(shopify_resource, (shopify.Order, shopify.Customer)):
raiseNotImplementedError(f"Objects of type {type(shopify_resource)} are not supported")
metafields=shopify_resource.metafields()
fori, metafieldinenumerate(metafields):
ifmetafield.namespace==metafield_config["namespace"] andmetafield.key==metafield_config["key"]:
returnmetafieldreturnshopify.Metafield(metafield_config)
fororder_id, other_idinorders_info.items():
order=shopify.Order.find(id_=order_id)
metafield=get_metafield(order, METAFIELD_CONFIG)
ifmetafield.valueisNone:
metafield.value=other_idreturnorder.add_metafield(metafield)
Sometimes I just trigger the pipeline again and it works normally... any ideas?
The text was updated successfully, but these errors were encountered:
As part of our data pipeline, there is a step where we update the metafields of an order to include custom business information. This logic was implemented successfully and had been functioning correctly for some time.
However, starting approximately one month ago, the code began to fail sometimes with the following error:
My code looks like this:
Sometimes I just trigger the pipeline again and it works normally... any ideas?
The text was updated successfully, but these errors were encountered: