Skip to content

Commit

Permalink
🐛 Source Jira: fix bug when board doesn't support sprints (#26652)
Browse files Browse the repository at this point in the history
  • Loading branch information
bazarnov committed May 26, 2023
1 parent ae1c544 commit 80c1dce
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 255 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-jira/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.3.9
LABEL io.airbyte.version=0.3.10
LABEL io.airbyte.name=airbyte/source-jira
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ acceptance_tests:
expect_records:
path: "integration_tests/expected_records.jsonl"
empty_streams:
- name: "issue_properties"
bypass_reason: "unable to populate"
- name: "project_permission_schemes"
bypass_reason: "unable to populate"
- name: "screen_tab_fields"
bypass_reason: "unable to populate"
ignored_fields:
sprint_issues:
- name: updated
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-jira/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 68e63de2-bb83-4c7e-93fa-a8a9051e3993
dockerImageTag: 0.3.9
dockerImageTag: 0.3.10
maxSecondsBetweenMessages: 21600
dockerRepository: airbyte/source-jira
githubIssueLabel: source-jira
Expand Down
16 changes: 16 additions & 0 deletions airbyte-integrations/connectors/source-jira/source_jira/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class JiraStream(HttpStream, ABC):
extract_field: Optional[str] = None
api_v1 = False
skip_http_status_codes = []
raise_on_http_errors = True

def __init__(self, domain: str, projects: List[str], **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -92,6 +93,19 @@ def read_records(self, **kwargs) -> Iterable[Mapping[str, Any]]:
if not (self.skip_http_status_codes and e.response.status_code in self.skip_http_status_codes):
raise e

def should_retry(self, response: requests.Response) -> bool:
if response.status_code == requests.codes.bad_request:
# Refernce issue: https://github.com/airbytehq/oncall/issues/2133
# we should skip the slice with `board id` which doesn't support `sprints`
# it's generally applied to all streams that might have the same error hit in the future.
errors = response.json().get("errorMessages")
self.logger.error(f"Stream `{self.name}`. An error occured, details: {errors}. Skipping.")
setattr(self, "raise_on_http_errors", False)
return False
else:
# for all other HTTP errors the defaul handling is applied
return super().should_retry(response)


class StartDateJiraStream(JiraStream, ABC):
def __init__(self, start_date: Optional[pendulum.DateTime] = None, **kwargs):
Expand Down Expand Up @@ -1083,6 +1097,8 @@ def read_records(self, stream_slice: Optional[Mapping[str, Any]] = None, **kwarg
available_board_types = ["scrum", "simple"]
for board in read_full_refresh(self.boards_stream):
if board["type"] in available_board_types:
board_details = {"name": board["name"], "id": board["id"]}
self.logger.info(f"Fetching sprints for board: {board_details}")
yield from super().read_records(stream_slice={"board_id": board["id"]}, **kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import pytest
import requests
import responses
from airbyte_cdk.models import SyncMode
from requests.exceptions import HTTPError
Expand Down Expand Up @@ -479,6 +480,19 @@ def test_sprints_stream(config, sprints_response):
assert len(responses.calls) == 3


@responses.activate
def test_board_does_not_support_sprints(config):
url = f"https://{config['domain']}/rest/agile/1.0/board/4/sprint?maxResults=50"
error = {'errorMessages': ['The board does not support sprints'], 'errors': {}}
responses.add(responses.GET, url, json=error,status=400)
authenticator = SourceJira().get_authenticator(config=config)
args = {"authenticator": authenticator, "domain": config["domain"], "projects": config.get("projects", [])}
stream = Sprints(**args)
response = requests.get(url)
actual = stream.should_retry(response)
assert actual is False


@responses.activate
def test_sprint_issues_stream(config, sprints_issues_response):
responses.add(
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/jira.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The Jira connector should not run into Jira API limitations under normal usage.

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------|
| 0.3.10 | 2023-05-26 | [\#26652](https://github.com/airbytehq/airbyte/pull/26652) | Fixed bug when `board` doesn't support `sprints` |
| 0.3.9 | 2023-05-16 | [\#26114](https://github.com/airbytehq/airbyte/pull/26114) | Update fields info in docs and spec, update to latest airbyte-cdk |
| 0.3.8 | 2023-05-04 | [\#25798](https://github.com/airbytehq/airbyte/pull/25798) | Add sprint info to `sprint_issues` and `sprints` streams for team-managed projects |
| 0.3.7 | 2023-04-18 | [\#25275](https://github.com/airbytehq/airbyte/pull/25275) | Add missing types to issues json schema |
Expand Down

0 comments on commit 80c1dce

Please sign in to comment.