Skip to content

πŸ› Source Zendesk Support: fix parse response for ticket metrics #37450

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

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715
dockerImageTag: 2.4.0
dockerImageTag: 2.4.1
dockerRepository: airbyte/source-zendesk-support
documentationUrl: https://docs.airbyte.com/integrations/sources/zendesk-support
githubIssueLabel: source-zendesk-support
Expand All @@ -26,7 +26,6 @@ data:
registries:
cloud:
enabled: true
dockerImageTag: 2.3.0 # See https://github.com/airbytehq/oncall/issues/5078
oss:
enabled: true
releaseStage: generally_available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.4.0"
version = "2.4.1"
name = "source-zendesk-support"
description = "Source implementation for Zendesk Support."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ def stream_slices(
for record in parent_records:
yield {"ticket_id": record["id"]}

def should_retry(self, response: requests.Response) -> bool:
if response.status_code == 404:
# not found in case of deleted ticket
setattr(self, "raise_on_http_errors", False)
return False
return super().should_retry(response)


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

if not self.cursor_field:
yield data
else:
cursor_date = (stream_state or {}).get(self.cursor_field)
updated = data[self.cursor_field]
if not cursor_date or updated >= cursor_date:
# no data in case of http errors
if data:
if not self.cursor_field:
yield data
else:
cursor_date = (stream_state or {}).get(self.cursor_field)
updated = data[self.cursor_field]
if not cursor_date or updated >= cursor_date:
yield data


class TicketSkips(CursorPaginationZendeskSupportStream):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,32 @@ def test_ticket_metrics_parse_response(self, stream_state, response, expected_re
records = list(stream.parse_response(mocked_response, stream_state=stream_state))
assert records == [{"id": "test id", "updated_at": "2024-04-17T19:34:06Z"}]

def test_read_ticket_metrics_with_error(self, requests_mock):
stream = get_stream_instance(TicketMetrics, STREAM_ARGS)
requests_mock.get(
f"https://sandbox.zendesk.com/api/v2/tickets/13/metrics",
json={"error": "RecordNotFound", "description": "Not found"}
)

records = list(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice={"ticket_id": "13"}))

assert records == []

@pytest.mark.parametrize(
"status_code, should_retry",
(
(200, False),
(404, False),
(403, False),
(500, True),
(429, True),
)
)
def test_ticket_metrics_should_retry(self, status_code, should_retry):
stream = get_stream_instance(TicketMetrics, STREAM_ARGS)
mocked_response = Mock(status_code=status_code)
assert stream.should_retry(mocked_response) == should_retry


def test_read_ticket_audits_504_error(requests_mock, caplog):
requests_mock.get("https://subdomain.zendesk.com/api/v2/ticket_audits", status_code=504, text="upstream request timeout")
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The Zendesk connector ideally should not run into Zendesk API limitations under

| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `2.4.1` | 2024-04-20 | [37450](https://github.com/airbytehq/airbyte/pull/37450) | Fix parsing response for`Ticket Metrics` stream. |
| `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. |
| `2.3.0` | 2024-03-26 | [36403](https://github.com/airbytehq/airbyte/pull/36403) | Unpin CDK version, add record counts to state messages |
| `2.2.8` | 2024-02-09 | [35083](https://github.com/airbytehq/airbyte/pull/35083) | Manage dependencies with Poetry. |
Expand Down
Loading