Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<urlopen error [Errno 101] Network is unreachable> #48

Open
hec10r opened this issue Jul 23, 2024 · 0 comments
Open

<urlopen error [Errno 101] Network is unreachable> #48

hec10r opened this issue Jul 23, 2024 · 0 comments

Comments

@hec10r
Copy link

hec10r commented Jul 23, 2024

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,
}

def get_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.
    """
    if not isinstance(shopify_resource, (shopify.Order, shopify.Customer)):
        raise NotImplementedError(f"Objects of type {type(shopify_resource)} are not supported")

    metafields = shopify_resource.metafields()

    for i, metafield in enumerate(metafields):
        if metafield.namespace == metafield_config["namespace"] and metafield.key == metafield_config["key"]:
            return metafield

    return shopify.Metafield(metafield_config)

for order_id, other_id in orders_info.items():
    order = shopify.Order.find(id_=order_id)
    metafield = get_metafield(order, METAFIELD_CONFIG)

    if metafield.value is None:
        metafield.value = other_id

    return order.add_metafield(metafield)

Sometimes I just trigger the pipeline again and it works normally... any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant