Skip to content

Commit

Permalink
🐛 Source Freshdesk: skip the stream if forbidden for current subscr…
Browse files Browse the repository at this point in the history
…iption plan (#17243)
  • Loading branch information
bazarnov committed Sep 27, 2022
1 parent 765bd1b commit a088206
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
- name: Freshdesk
sourceDefinitionId: ec4b9503-13cb-48ab-a4ab-6ade4be46567
dockerRepository: airbyte/source-freshdesk
dockerImageTag: 0.3.3
dockerImageTag: 0.3.4
documentationUrl: https://docs.airbyte.io/integrations/sources/freshdesk
icon: freshdesk.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-freshdesk:0.3.3"
- dockerImage: "airbyte/source-freshdesk:0.3.4"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/freshdesk"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ COPY source_freshdesk ./source_freshdesk
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.3.3
LABEL io.airbyte.version=0.3.4
LABEL io.airbyte.name=airbyte/source-freshdesk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class FreshdeskStream(HttpStream, ABC):
result_return_limit = 100
primary_key = "id"
link_regex = re.compile(r'<(.*?)>;\s*rel="next"')
raise_on_http_errors = True
forbidden_stream = False

def __init__(self, authenticator: AuthBase, config: Mapping[str, Any], *args, **kwargs):
super().__init__(authenticator=authenticator)
Expand All @@ -44,6 +46,16 @@ def backoff_time(self, response: requests.Response) -> Optional[float]:
if response.status_code == requests.codes.too_many_requests:
return float(response.headers.get("Retry-After", 0))

def should_retry(self, response: requests.Response) -> bool:
if isinstance(response.json(), dict):
if response.status_code == requests.codes.FORBIDDEN and response.json().get("code") == "require_feature":
self.forbidden_stream = True
setattr(self, "raise_on_http_errors", False)
self.logger.warn(f"Stream `{self.name}` is not available. {response.json().get('message')}")
else:
return super().should_retry(response)
return super().should_retry(response)

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
link_header = response.headers.get("Link")
if not link_header:
Expand All @@ -57,7 +69,7 @@ def parse_link_params(self, link_query_params: Mapping[str, List[str]]) -> Mappi
return {"per_page": link_query_params["per_page"][0], "page": link_query_params["page"][0]}

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> MutableMapping[str, Any]:
params = {"per_page": self.result_return_limit}
if next_page_token and "page" in next_page_token:
Expand All @@ -83,7 +95,7 @@ def read_records(

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
data = response.json()
return data if data else []
return {} if self.forbidden_stream else data if data else []


class IncrementalFreshdeskStream(FreshdeskStream, IncrementalMixin):
Expand All @@ -108,7 +120,7 @@ def state(self, value: MutableMapping[str, Any]):
self._cursor_value = value.get(self.cursor_field, self.start_date)

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> MutableMapping[str, Any]:
params = super().request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token)
params[self.cursor_filter] = stream_state.get(self.cursor_field, self.start_date)
Expand Down Expand Up @@ -301,7 +313,7 @@ def path(self, **kwargs) -> str:
return "tickets"

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> MutableMapping[str, Any]:
params = super().request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token)
includes = ["description", "requester", "stats"]
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/freshdesk.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The Freshdesk connector should not run into Freshdesk API limitations under norm

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:------------------------------------------------------------|:-------------------------------------------------------------------------------|
| 0.3.4 | 2022-09-27 | [17243](https://github.com/airbytehq/airbyte/pull/17243) | Fixed the issue, when selected stream is not available due to Subscription Plan.
| 0.3.3 | 2022-08-06 | [15378](https://github.com/airbytehq/airbyte/pull/15378) | Allow backward campatibility for input configuration
| 0.3.2 | 2022-06-23 | [14049](https://github.com/airbytehq/airbyte/pull/14049) | Update parsing of start_date |
| 0.3.1 | 2022-06-03 | [13332](https://github.com/airbytehq/airbyte/pull/13332) | Add new streams |
Expand Down

0 comments on commit a088206

Please sign in to comment.