Skip to content

Commit b339f1b

Browse files
🐛 Source Zendesk Support: fix parse response for ticket metrics (#37450)
1 parent fce3409 commit b339f1b

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

airbyte-integrations/connectors/source-zendesk-support/metadata.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data:
1111
connectorSubtype: api
1212
connectorType: source
1313
definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715
14-
dockerImageTag: 2.4.0
14+
dockerImageTag: 2.4.1
1515
dockerRepository: airbyte/source-zendesk-support
1616
documentationUrl: https://docs.airbyte.com/integrations/sources/zendesk-support
1717
githubIssueLabel: source-zendesk-support
@@ -26,7 +26,6 @@ data:
2626
registries:
2727
cloud:
2828
enabled: true
29-
dockerImageTag: 2.3.0 # See https://github.com/airbytehq/oncall/issues/5078
3029
oss:
3130
enabled: true
3231
releaseStage: generally_available

airbyte-integrations/connectors/source-zendesk-support/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
6-
version = "2.4.0"
6+
version = "2.4.1"
77
name = "source-zendesk-support"
88
description = "Source implementation for Zendesk Support."
99
authors = [ "Airbyte <[email protected]>",]

airbyte-integrations/connectors/source-zendesk-support/source_zendesk_support/streams.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ def stream_slices(
517517
for record in parent_records:
518518
yield {"ticket_id": record["id"]}
519519

520+
def should_retry(self, response: requests.Response) -> bool:
521+
if response.status_code == 404:
522+
# not found in case of deleted ticket
523+
setattr(self, "raise_on_http_errors", False)
524+
return False
525+
return super().should_retry(response)
526+
520527

521528
class TicketComments(SourceZendeskSupportTicketEventsExportStream):
522529
"""
@@ -604,13 +611,15 @@ def parse_response(self, response: requests.Response, stream_state: Mapping[str,
604611
except requests.exceptions.JSONDecodeError:
605612
data = {}
606613

607-
if not self.cursor_field:
608-
yield data
609-
else:
610-
cursor_date = (stream_state or {}).get(self.cursor_field)
611-
updated = data[self.cursor_field]
612-
if not cursor_date or updated >= cursor_date:
614+
# no data in case of http errors
615+
if data:
616+
if not self.cursor_field:
613617
yield data
618+
else:
619+
cursor_date = (stream_state or {}).get(self.cursor_field)
620+
updated = data[self.cursor_field]
621+
if not cursor_date or updated >= cursor_date:
622+
yield data
614623

615624

616625
class TicketSkips(CursorPaginationZendeskSupportStream):

airbyte-integrations/connectors/source-zendesk-support/unit_tests/unit_test.py

+26
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,32 @@ def test_ticket_metrics_parse_response(self, stream_state, response, expected_re
11551155
records = list(stream.parse_response(mocked_response, stream_state=stream_state))
11561156
assert records == [{"id": "test id", "updated_at": "2024-04-17T19:34:06Z"}]
11571157

1158+
def test_read_ticket_metrics_with_error(self, requests_mock):
1159+
stream = get_stream_instance(TicketMetrics, STREAM_ARGS)
1160+
requests_mock.get(
1161+
f"https://sandbox.zendesk.com/api/v2/tickets/13/metrics",
1162+
json={"error": "RecordNotFound", "description": "Not found"}
1163+
)
1164+
1165+
records = list(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice={"ticket_id": "13"}))
1166+
1167+
assert records == []
1168+
1169+
@pytest.mark.parametrize(
1170+
"status_code, should_retry",
1171+
(
1172+
(200, False),
1173+
(404, False),
1174+
(403, False),
1175+
(500, True),
1176+
(429, True),
1177+
)
1178+
)
1179+
def test_ticket_metrics_should_retry(self, status_code, should_retry):
1180+
stream = get_stream_instance(TicketMetrics, STREAM_ARGS)
1181+
mocked_response = Mock(status_code=status_code)
1182+
assert stream.should_retry(mocked_response) == should_retry
1183+
11581184

11591185
def test_read_ticket_audits_504_error(requests_mock, caplog):
11601186
requests_mock.get("https://subdomain.zendesk.com/api/v2/ticket_audits", status_code=504, text="upstream request timeout")

docs/integrations/sources/zendesk-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ The Zendesk connector ideally should not run into Zendesk API limitations under
158158

159159
| Version | Date | Pull Request | Subject |
160160
|:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
161+
| `2.4.1` | 2024-04-20 | [37450](https://github.com/airbytehq/airbyte/pull/37450) | Fix parsing response for`Ticket Metrics` stream. |
161162
| `2.4.0` | 2024-04-09 | [36897](https://github.com/airbytehq/airbyte/pull/36897) | Fix long-running syncs for `Ticket Metrics`, `Ticket Audits` and `Satisfaction Ratings` streams. |
162163
| `2.3.0` | 2024-03-26 | [36403](https://github.com/airbytehq/airbyte/pull/36403) | Unpin CDK version, add record counts to state messages |
163164
| `2.2.8` | 2024-02-09 | [35083](https://github.com/airbytehq/airbyte/pull/35083) | Manage dependencies with Poetry. |

0 commit comments

Comments
 (0)