From 8f927980929befa5ae44d30248df3756b0cbb4d0 Mon Sep 17 00:00:00 2001 From: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:20:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Source=20Zendesk=20Support:=20Ad?= =?UTF-8?q?d=20handle=20404=20error=20(#28397)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add handle 404 error * Updated PR number * Updated version --- .../source-zendesk-support/Dockerfile | 2 +- .../source-zendesk-support/metadata.yaml | 2 +- .../source_zendesk_support/streams.py | 8 +++++--- .../unit_tests/unit_test.py | 20 +++++++++++++------ docs/integrations/sources/zendesk-support.md | 3 ++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/airbyte-integrations/connectors/source-zendesk-support/Dockerfile b/airbyte-integrations/connectors/source-zendesk-support/Dockerfile index df289402427c..3ec359bb0039 100644 --- a/airbyte-integrations/connectors/source-zendesk-support/Dockerfile +++ b/airbyte-integrations/connectors/source-zendesk-support/Dockerfile @@ -25,5 +25,5 @@ COPY source_zendesk_support ./source_zendesk_support ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=0.10.3 +LABEL io.airbyte.version=0.10.4 LABEL io.airbyte.name=airbyte/source-zendesk-support diff --git a/airbyte-integrations/connectors/source-zendesk-support/metadata.yaml b/airbyte-integrations/connectors/source-zendesk-support/metadata.yaml index f987721e46b4..7a77a2213c05 100644 --- a/airbyte-integrations/connectors/source-zendesk-support/metadata.yaml +++ b/airbyte-integrations/connectors/source-zendesk-support/metadata.yaml @@ -7,7 +7,7 @@ data: connectorType: source maxSecondsBetweenMessages: 10800 definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715 - dockerImageTag: 0.10.3 + dockerImageTag: 0.10.4 dockerRepository: airbyte/source-zendesk-support githubIssueLabel: source-zendesk-support icon: zendesk-support.svg diff --git a/airbyte-integrations/connectors/source-zendesk-support/source_zendesk_support/streams.py b/airbyte-integrations/connectors/source-zendesk-support/source_zendesk_support/streams.py index 11bcb8075902..7f8431951854 100644 --- a/airbyte-integrations/connectors/source-zendesk-support/source_zendesk_support/streams.py +++ b/airbyte-integrations/connectors/source-zendesk-support/source_zendesk_support/streams.py @@ -119,11 +119,13 @@ def parse_response(self, response: requests.Response, stream_state: Mapping[str, yield record def should_retry(self, response: requests.Response) -> bool: - if response.status_code == 403: + status_code = response.status_code + if status_code == 403 or status_code == 404: try: error = response.json().get("error") except requests.exceptions.JSONDecodeError: - error = {"title": "Forbidden", "message": "Received empty JSON response"} + reason = response.reason + error = {"title": f"{reason}", "message": "Received empty JSON response"} self.logger.error(f"Skipping stream {self.name}: Check permissions, error message: {error}.") setattr(self, "raise_on_http_errors", False) return False @@ -227,7 +229,7 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, if self._ignore_pagination: return None - meta = response.json().get("meta", {}) + meta = response.json().get("meta", {}) if response.content else {} return {"page[after]": meta.get("after_cursor")} if meta.get("has_more") else None def request_params( diff --git a/airbyte-integrations/connectors/source-zendesk-support/unit_tests/unit_test.py b/airbyte-integrations/connectors/source-zendesk-support/unit_tests/unit_test.py index 99136c0bba28..12eeba8b99c1 100644 --- a/airbyte-integrations/connectors/source-zendesk-support/unit_tests/unit_test.py +++ b/airbyte-integrations/connectors/source-zendesk-support/unit_tests/unit_test.py @@ -140,20 +140,28 @@ def test_check(response, start_date, check_passed): @pytest.mark.parametrize( - "ticket_forms_response, status_code, expected_n_streams, expected_warnings", + "ticket_forms_response, status_code, expected_n_streams, expected_warnings, reason", [ - ({"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}, 200, 27, []), + ('{"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}', 200, 27, [], None), ( - {"error": "Not sufficient permissions"}, + '{"error": "Not sufficient permissions"}', 403, 24, ["Skipping stream ticket_forms: Check permissions, error message: Not sufficient permissions."], + None + ), + ( + '', + 404, + 24, + ["Skipping stream ticket_forms: Check permissions, error message: {'title': 'Not Found', 'message': 'Received empty JSON response'}."], + 'Not Found' ), ], - ids=["forms_accessible", "forms_inaccessible"], + ids=["forms_accessible", "forms_inaccessible", "forms_not_exists"], ) -def test_full_access_streams(caplog, requests_mock, ticket_forms_response, status_code, expected_n_streams, expected_warnings): - requests_mock.get("/api/v2/ticket_forms", status_code=status_code, json=ticket_forms_response) +def test_full_access_streams(caplog, requests_mock, ticket_forms_response, status_code, expected_n_streams, expected_warnings, reason): + requests_mock.get("/api/v2/ticket_forms", status_code=status_code, text=ticket_forms_response, reason=reason) result = SourceZendeskSupport().streams(config=TEST_CONFIG) assert len(result) == expected_n_streams logged_warnings = iter([record for record in caplog.records if record.levelname == "ERROR"]) diff --git a/docs/integrations/sources/zendesk-support.md b/docs/integrations/sources/zendesk-support.md index 097142e71c48..6c0bcfd53070 100644 --- a/docs/integrations/sources/zendesk-support.md +++ b/docs/integrations/sources/zendesk-support.md @@ -79,10 +79,11 @@ The Zendesk connector ideally should not run into Zendesk API limitations under | Version | Date | Pull Request | Subject | |:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `0.10.4` | 2023-07-25 | [28397](https://github.com/airbytehq/airbyte/pull/28397) | Handle 404 Error | | `0.10.3` | 2023-07-24 | [28612](https://github.com/airbytehq/airbyte/pull/28612) | Fix pagination for stream `TicketMetricEvents` | | `0.10.2` | 2023-07-19 | [28487](https://github.com/airbytehq/airbyte/pull/28487) | Remove extra page from params | | `0.10.1` | 2023-07-10 | [28096](https://github.com/airbytehq/airbyte/pull/28096) | Replace `offset` pagination with `cursor` pagination | -| `0.10.0` | 2023-07-06 | [27991](https://github.com/airbytehq/airbyte/pull/27991) | add streams: `PostVotes`, `PostCommentVotes` | +| `0.10.0` | 2023-07-06 | [27991](https://github.com/airbytehq/airbyte/pull/27991) | Add streams: `PostVotes`, `PostCommentVotes` | | `0.9.0` | 2023-07-05 | [27961](https://github.com/airbytehq/airbyte/pull/27961) | Add stream: `Post Comments` | | `0.8.1` | 2023-06-27 | [27765](https://github.com/airbytehq/airbyte/pull/27765) | Bugfix: Nonetype error while syncing more then 100000 organizations | | `0.8.0` | 2023-06-09 | [27156](https://github.com/airbytehq/airbyte/pull/27156) | Add stream `Posts` |