Skip to content

Commit

Permalink
Add metafields method to ProductCompatability and update callsites
Browse files Browse the repository at this point in the history
  • Loading branch information
nassredean committed Jan 17, 2025
1 parent 401e670 commit 5e4b85f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
14 changes: 7 additions & 7 deletions tap_shopify/streams/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def retry_after_wait_gen(**kwargs):
yield math.ceil(float(sleep_time_str))

def shopify_error_handling(fnc):
@backoff.on_exception(backoff.expo,
(pyactiveresource.connection.ServerError,
pyactiveresource.formats.Error,
simplejson.scanner.JSONDecodeError,
Exception),
on_backoff=retry_handler,
max_tries=MAX_RETRIES)
# @backoff.on_exception(backoff.expo,
# (pyactiveresource.connection.ServerError,
# pyactiveresource.formats.Error,
# simplejson.scanner.JSONDecodeError,
# Exception),
# on_backoff=retry_handler,
# max_tries=MAX_RETRIES)
@backoff.on_exception(retry_after_wait_gen,
pyactiveresource.connection.ClientError,
giveup=is_not_status_code_fn([429]),
Expand Down
8 changes: 8 additions & 0 deletions tap_shopify/streams/compatibility/product_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import json
import os
import shopify.resources

class ProductCompatibility():
def __init__(self, graphql_product):
"""Initialize with a GraphQL product object."""
self.graphql_product = graphql_product
self.admin_graphql_api_id = graphql_product["id"]
self.product_id = self._extract_int_id(graphql_product["id"])

current_dir = os.path.dirname(os.path.abspath(__file__))
value_map_path = os.path.join(current_dir, "value_maps", "product.json")
with open(value_map_path, 'r') as file:
self.value_map = json.load(file)

def metafields(self, _options=None, **kwargs):
if _options is None:
_options = kwargs
return shopify.resources.Metafield.find(resource="products", resource_id=self.product_id, **_options)

def _extract_int_id(self, string_id):
return int(string_id.split("/")[-1])

Expand Down
6 changes: 3 additions & 3 deletions tap_shopify/streams/inventory_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_objects(self):

# Page through all `products`, bookmarking at `product_variants`
for parent_object in selected_parent.get_objects():

product_variants = parent_object.variants
product_dict = parent_object.to_dict()
product_variants = product_dict["variants"]
inventory_items_ids = ",".join(
[str(product_variant.inventory_item_id) for product_variant in product_variants])
[str(product_variant["inventory_item_id"]) for product_variant in product_variants])

# Max limit of IDs is 100 and Max limit of product_variants in one product is also 100
# hence we can directly pass all inventory_items_ids
Expand Down
2 changes: 1 addition & 1 deletion tap_shopify/streams/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sync(self):
for incoming_item in self.get_objects():
replication_value = strptime_to_utc(incoming_item[self.replication_key])
if replication_value >= bookmark:

yield incoming_item
if replication_value > self.max_bookmark:
self.max_bookmark = replication_value
Expand Down

0 comments on commit 5e4b85f

Please sign in to comment.