Skip to content

Commit

Permalink
🐛 Source Facebook Marketing: Add temporary OAuth error handling (#10917)
Browse files Browse the repository at this point in the history
* Add temporary oauth error handling

* Updated PR number

* Update docs/integrations/sources/facebook-marketing.md

Co-authored-by: Sherif A. Nada <snadalive@gmail.com>

* Updated version and unittests

* Deleted typo

* Updated to linter

* Bumped version

Co-authored-by: Sherif A. Nada <snadalive@gmail.com>
  • Loading branch information
lazebnyi and sherifnada committed Mar 10, 2022
1 parent 1bf9470 commit c6caf14
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
- name: Facebook Marketing
sourceDefinitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
dockerRepository: airbyte/source-facebook-marketing
dockerImageTag: 0.2.38
dockerImageTag: 0.2.39
documentationUrl: https://docs.airbyte.io/integrations/sources/facebook-marketing
icon: facebook.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-facebook-marketing:0.2.38"
- dockerImage: "airbyte/source-facebook-marketing:0.2.39"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"
changelogUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"
Expand Down
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.2.38
LABEL io.airbyte.version=0.2.39
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# The Facebook API error codes indicating rate-limiting are listed at
# https://developers.facebook.com/docs/graph-api/overview/rate-limiting/
FACEBOOK_RATE_LIMIT_ERROR_CODES = (4, 17, 32, 613, 80000, 80001, 80002, 80003, 80004, 80005, 80006, 80008)
FACEBOOK_TEMPORARY_OAUTH_ERROR_CODE = 2
FACEBOOK_BATCH_ERROR_CODE = 960
FACEBOOK_UNKNOWN_ERROR_CODE = 99
FACEBOOK_CONNECTION_RESET_ERROR_CODE = 104
Expand All @@ -36,12 +37,21 @@ def log_retry_attempt(details):
def should_retry_api_error(exc):
if isinstance(exc, FacebookRequestError):
call_rate_limit_error = exc.api_error_code() in FACEBOOK_RATE_LIMIT_ERROR_CODES
temporary_oauth_error = exc.api_error_code() == FACEBOOK_TEMPORARY_OAUTH_ERROR_CODE
batch_timeout_error = exc.http_status() == http.client.BAD_REQUEST and exc.api_error_code() == FACEBOOK_BATCH_ERROR_CODE
unknown_error = exc.api_error_subcode() == FACEBOOK_UNKNOWN_ERROR_CODE
connection_reset_error = exc.api_error_code() == FACEBOOK_CONNECTION_RESET_ERROR_CODE
server_error = exc.http_status() == http.client.INTERNAL_SERVER_ERROR
return any(
(exc.api_transient_error(), unknown_error, call_rate_limit_error, batch_timeout_error, connection_reset_error, server_error)
(
exc.api_transient_error(),
unknown_error,
call_rate_limit_error,
batch_timeout_error,
connection_reset_error,
temporary_oauth_error,
server_error,
)
)
return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def test_batch_limit_reached(self, requests_mock, api, fb_call_rate_response, ac
[
{"json": {"error": {}}, "status_code": 500},
{"json": {"error": {"code": 104}}},
{"json": {"error": {"code": 2}}, "status_code": 500},
],
ids=["server_error", "connection_reset_error"],
ids=["server_error", "connection_reset_error", "temporary_oauth_error"],
)
def test_common_error_retry(self, error_response, requests_mock, api, account_id):
"""Error once, check that we retry and not fail"""
Expand Down
5 changes: 3 additions & 2 deletions docs/integrations/sources/facebook-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ As a summary, custom insights allows to replicate only some fields, resulting in

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.38 | 2022-02-22 | [10531](https://github.com/airbytehq/airbyte/pull/10531) | Add `time_increment` parameter to custom insights |
| 0.2.39 | 2022-03-09 | [10917](https://github.com/airbytehq/airbyte/pull/10917) | retry connections when FB API returns error code 2 (temporary oauth error) |
| 0.2.38 | 2022-03-08 | [10531](https://github.com/airbytehq/airbyte/pull/10531) | Add `time_increment` parameter to custom insights |
| 0.2.37 | 2022-02-28 | [10655](https://github.com/airbytehq/airbyte/pull/10655) | Add Activities stream |
| 0.2.36 | 2022-02-24 | [10588](https://github.com/airbytehq/airbyte/pull/10588) | Fix `execute_in_batch` for large amount of requests |
| 0.2.35 | 2022-02-18 | [10348](https://github.com/airbytehq/airbyte/pull/10348) | Add 104 error code to backoff triggers |
| 0.2.35 | 2022-02-18 | [10348](https://github.com/airbytehq/airbyte/pull/10348) | Add error code 104 to backoff triggers |
| 0.2.34 | 2022-02-17 | [10180](https://github.com/airbytehq/airbyte/pull/9805) | Performance and reliability fixes |
| 0.2.33 | 2021-12-28 | [10180](https://github.com/airbytehq/airbyte/pull/10180) | Add AdAccount and Images streams |
| 0.2.32 | 2022-01-07 | [10138](https://github.com/airbytehq/airbyte/pull/10138) | Add `primary_key` for all insights streams. |
Expand Down

0 comments on commit c6caf14

Please sign in to comment.