Skip to content

Commit 4aecd3f

Browse files
authored
🎉 Source Stripe:: improve 404 handling for CheckoutSessionsLineItems stream (#10165)
* Improve 404 handling for CheckoutSessionsLineItems stream Signed-off-by: Sergey Chvalyuk <[email protected]>
1 parent 84d1456 commit 4aecd3f

File tree

9 files changed

+67
-4
lines changed

9 files changed

+67
-4
lines changed

‎airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/e094cb9a-26de-4645-8761-65c0c425d1de.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"sourceDefinitionId": "e094cb9a-26de-4645-8761-65c0c425d1de",
33
"name": "Stripe",
44
"dockerRepository": "airbyte/source-stripe",
5-
"dockerImageTag": "0.1.27",
5+
"dockerImageTag": "0.1.28",
66
"documentationUrl": "https://docs.airbyte.io/integrations/sources/stripe",
77
"icon": "stripe.svg"
88
}

‎airbyte-config/init/src/main/resources/seed/source_definitions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@
724724
- name: Stripe
725725
sourceDefinitionId: e094cb9a-26de-4645-8761-65c0c425d1de
726726
dockerRepository: airbyte/source-stripe
727-
dockerImageTag: 0.1.27
727+
dockerImageTag: 0.1.28
728728
documentationUrl: https://docs.airbyte.io/integrations/sources/stripe
729729
icon: stripe.svg
730730
sourceType: api

‎airbyte-config/init/src/main/resources/seed/source_specs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7713,7 +7713,7 @@
77137713
type: "string"
77147714
path_in_connector_config:
77157715
- "client_secret"
7716-
- dockerImage: "airbyte/source-stripe:0.1.27"
7716+
- dockerImage: "airbyte/source-stripe:0.1.28"
77177717
spec:
77187718
documentationUrl: "https://docs.airbyte.io/integrations/sources/stripe"
77197719
connectionSpecification:

‎airbyte-integrations/connectors/source-stripe/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.1.27
15+
LABEL io.airbyte.version=0.1.28
1616
LABEL io.airbyte.name=airbyte/source-stripe

‎airbyte-integrations/connectors/source-stripe/acceptance-test-config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ tests:
3838
configured_catalog_path: "integration_tests/full_refresh_configured_catalog.json"
3939
- config_path: "secrets/connected_account_config.json"
4040
configured_catalog_path: "integration_tests/connected_account_configured_catalog.json"
41+
ignored_fields:
42+
"invoices":
43+
- invoice_pdf
44+
- hosted_invoice_url

‎airbyte-integrations/connectors/source-stripe/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
TEST_REQUIREMENTS = [
1111
"pytest~=6.1",
12+
"requests-mock",
1213
]
1314

1415
setup(

‎airbyte-integrations/connectors/source-stripe/source_stripe/streams.py

+8
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,15 @@ def request_params(self, stream_slice: Mapping[str, Any] = None, **kwargs):
380380
params["expand[]"] = ["data.discounts", "data.taxes"]
381381
return params
382382

383+
@property
384+
def raise_on_http_errors(self):
385+
return False
386+
383387
def parse_response(self, response: requests.Response, stream_slice: Mapping[str, Any] = None, **kwargs) -> Iterable[Mapping]:
388+
if response.status_code == 404:
389+
self.logger.warning(response.json())
390+
return
391+
response.raise_for_status()
384392

385393
response_json = response.json()
386394
data = response_json.get("data", [])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
from airbyte_cdk.models import SyncMode
7+
from source_stripe.streams import CheckoutSessionsLineItems
8+
9+
10+
def test_missed_id_child_stream(requests_mock):
11+
12+
session_id_missed = "cs_test_a165K4wNihuJlp2u3tknuohrvjAxyXFUB7nxZH3lwXRKJsadNEvIEWMUJ9"
13+
session_id_exists = "cs_test_a1RjRHNyGUQOFVF3OkL8V8J0lZUASyVoCtsnZYG74VrBv3qz4245BLA1BP"
14+
15+
response_sessions = {
16+
"data": [{"id": session_id_missed}, {"id": session_id_exists}],
17+
"has_more": False,
18+
"object": "list",
19+
"url": "/v1/checkout/sessions",
20+
}
21+
22+
response_sessions_line_items = {
23+
"data": [{"id": "li_1JpAUUIEn5WyEQxnfGJT5MbL"}],
24+
"has_more": False,
25+
"object": "list",
26+
"url": "/v1/checkout/sessions/{}/line_items".format(session_id_exists),
27+
}
28+
29+
response_error = {
30+
"error": {
31+
"code": "resource_missing",
32+
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
33+
"message": "No such checkout session: '{}'".format(session_id_missed),
34+
"param": "session",
35+
"type": "invalid_request_error",
36+
}
37+
}
38+
39+
requests_mock.get("https://api.stripe.com/v1/checkout/sessions", json=response_sessions)
40+
requests_mock.get(
41+
"https://api.stripe.com/v1/checkout/sessions/{}/line_items".format(session_id_exists), json=response_sessions_line_items
42+
)
43+
requests_mock.get(
44+
"https://api.stripe.com/v1/checkout/sessions/{}/line_items".format(session_id_missed), json=response_error, status_code=404
45+
)
46+
47+
stream = CheckoutSessionsLineItems(start_date=None, account_id=None)
48+
records = list(stream.read_records(sync_mode=SyncMode.full_refresh))
49+
assert len(records) == 1

‎docs/integrations/sources/stripe.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ If you would like to test Airbyte using test data on Stripe, `sk_test_` and `rk_
7474

7575
| Version | Date | Pull Request | Subject |
7676
| :--- | :--- | :--- | :--- |
77+
| 0.1.28 | 2022-02-08 | [10165](https://github.com/airbytehq/airbyte/pull/10165) | Improve 404 handling for `CheckoutSessionsLineItems` stream |
7778
| 0.1.27 | 2021-12-28 | [9148](https://github.com/airbytehq/airbyte/pull/9148) | Fix `date`, `arrival\_date` fields |
7879
| 0.1.26 | 2021-12-21 | [8992](https://github.com/airbytehq/airbyte/pull/8992) | Fix type `events.request` in schema |
7980
| 0.1.25 | 2021-11-25 | [8250](https://github.com/airbytehq/airbyte/pull/8250) | Rearrange setup fields |

0 commit comments

Comments
 (0)