Skip to content

Commit

Permalink
Source Snapchat Marketing: permission error (#20865)
Browse files Browse the repository at this point in the history
* Source Snapchat Marketing: permission error

* Source Snapchat Marketing: add test; docs update

* auto-bump connector version

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
artem1205 and octavia-squidington-iii authored Jan 4, 2023
1 parent abf3ef8 commit f5b793d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@
- name: Snapchat Marketing
sourceDefinitionId: 200330b2-ea62-4d11-ac6d-cfe3e3f8ab2b
dockerRepository: airbyte/source-snapchat-marketing
dockerImageTag: 0.1.10
dockerImageTag: 0.1.11
documentationUrl: https://docs.airbyte.com/integrations/sources/snapchat-marketing
icon: snapchat.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13617,7 +13617,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-snapchat-marketing:0.1.10"
- dockerImage: "airbyte/source-snapchat-marketing:0.1.11"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/snapchat-marketing"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ COPY source_snapchat_marketing ./source_snapchat_marketing
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.10
LABEL io.airbyte.version=0.1.11
LABEL io.airbyte.name=airbyte/source-snapchat-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def get_parent_ids(parent) -> List:
class SnapchatMarketingStream(HttpStream, ABC):
url_base = "https://adsapi.snapchat.com/v1/"
primary_key = "id"
raise_on_http_errors = True

def __init__(self, start_date, end_date, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -213,6 +214,13 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
raise SnapchatMarketingException(error_text)
yield resp.get(self.response_item_name)

def should_retry(self, response: requests.Response) -> bool:
if response.status_code == 403:
setattr(self, "raise_on_http_errors", False)
self.logger.warning(f"Got permission error when accessing URL {response.request.url}. " f"Skipping {self.name} stream.")
return False
return super().should_retry(response)


class IncrementalSnapchatMarketingStream(SnapchatMarketingStream, ABC):
cursor_field = "updated_at"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,12 @@ def test_retry_get_access_token(requests_mock):
token = auth.get_access_token()
assert len(requests_mock.request_history) == 3
assert token == "token"


def test_should_retry_403_error(requests_mock):
requests_mock.register_uri("GET", "https://adsapi.snapchat.com/v1/me/organizations",
[{"status_code": 403, "json": {"organizations": []}}])
stream = Organizations(**config_mock)
records = list(stream.read_records(sync_mode=SyncMode.full_refresh))

assert not records
1 change: 1 addition & 0 deletions docs/integrations/sources/snapchat-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Snapchat Marketing API has limitations to 1000 items per page.

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:------------------------------------------------------|
| 0.1.11 | 2022-12-23 | [20865](https://github.com/airbytehq/airbyte/pull/20865) | Handle 403 permission error |
| 0.1.10 | 2022-12-15 | [20537](https://github.com/airbytehq/airbyte/pull/20537) | Run on CDK 0.15.0 |
| 0.1.9 | 2022-12-14 | [20498](https://github.com/airbytehq/airbyte/pull/20498) | Fix output state when no records are read |
| 0.1.8 | 2022-10-05 | [17596](https://github.com/airbytehq/airbyte/pull/17596) | Retry 429 and 5xx errors when refreshing access token |
Expand Down

0 comments on commit f5b793d

Please sign in to comment.