Skip to content

Commit 859af9b

Browse files
authored
update the bookmark value even if the record is not retrieved (#247)
* update the bookmark value even if the record is not retrieved * setup and changelog update * add discount applications in the output * fix the test * fix copilot review comments
1 parent 2b61a0d commit 859af9b

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### 3.8.1
4+
* Update the bookmark value even if the record is not retrieved [#247](https://github.com/singer-io/tap-shopify/pull/247)
5+
36
### 3.8.0
47
* Exponential backoff for Shopify bulk operations in progress [#246](https://github.com/singer-io/tap-shopify/pull/246)
58

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="tap-shopify",
7-
version="3.8.0",
7+
version="3.8.1",
88
description="Singer.io tap for extracting Shopify data",
99
author="Stitch",
1010
url="http://github.com/singer-io/tap-shopify",

tap_shopify/streams/orders.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ def get_query(self):
10041004
code
10051005
}
10061006
... on ManualDiscountApplication {
1007+
__typename
10071008
title
10081009
description
10091010
}
@@ -1020,6 +1021,14 @@ def get_query(self):
10201021
}
10211022
"""
10221023

1024+
def is_discount_application(self, rec):
1025+
if '__typename' in rec and rec['__typename'] in ['AutomaticDiscountApplication',
1026+
'DiscountCodeApplication',
1027+
'ManualDiscountApplication',
1028+
'ScriptDiscountApplication']:
1029+
return True
1030+
return False
1031+
10231032
def update_bookmark(self, bookmark_value, bookmark_key=None, bulk_op_metadata=None):
10241033
# Standard Singer bookmark
10251034
singer.write_bookmark(
@@ -1163,6 +1172,7 @@ def parse_bulk_jsonl(self, url):
11631172
resp = requests.get(url, stream=True, timeout=60)
11641173
current_order = None
11651174
current_line_items = []
1175+
current_discount_applications = []
11661176

11671177
for line in resp.iter_lines():
11681178
if not line:
@@ -1173,18 +1183,25 @@ def parse_bulk_jsonl(self, url):
11731183
continue
11741184
# Detect line item (child) or order (parent)
11751185
if '__parentId' in rec:
1176-
# It's a line item belonging to current_order
1177-
current_line_items.append(rec)
1186+
if self.is_discount_application(rec):
1187+
# It's a discount application belonging to current_order
1188+
current_discount_applications.append(rec)
1189+
else:
1190+
# It's a line item belonging to current_order
1191+
current_line_items.append(rec)
11781192
else:
11791193
if current_order:
11801194
current_order["lineItems"] = current_line_items
1195+
current_order["discountApplications"] = current_discount_applications
11811196
yield current_order
11821197
# Start tracking new parent group
11831198
current_order = rec
11841199
current_line_items = []
1200+
current_discount_applications = []
11851201
# Yield the last parent group (if exists)
11861202
if current_order:
11871203
current_order["lineItems"] = current_line_items
1204+
current_order["discountApplications"] = current_discount_applications
11881205
yield current_order
11891206

11901207
def transform_object(self, obj):
@@ -1254,6 +1271,7 @@ def get_objects(self):
12541271
else:
12551272
LOGGER.info("No data returned for the date range: %s to %s",
12561273
last_updated_at, query_end)
1274+
current_bookmark = max(current_bookmark, query_end)
12571275

12581276
self.clear_bulk_operation_state()
12591277
last_updated_at = query_end

tests/test_all_fields.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
'canDelete',
1313
'rawMessage',
1414
'canEdit',
15-
},
16-
'orders': {'discountApplications'}
15+
}
1716
}
1817

1918
class AllFieldsTest(BaseTapTest):

0 commit comments

Comments
 (0)