Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Source Facebook Marketing: Fix backoff trigger with ConnectionError #10348

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.33
LABEL io.airbyte.version=0.2.34
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# 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_UNKNOWN_ERROR_CODE = 99
FACEBOOK_CONNECTION_RESET_ERROR_CODE = 104
DEFAULT_SLEEP_INTERVAL = pendulum.duration(minutes=1)

logger = logging.getLogger("airbyte")
Expand Down Expand Up @@ -47,7 +48,13 @@ 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
return exc.api_transient_error() or exc.api_error_subcode() == FACEBOOK_UNKNOWN_ERROR_CODE or call_rate_limit_error
call_connection_reset_error = exc.api_error_code() == FACEBOOK_CONNECTION_RESET_ERROR_CODE
return (
exc.api_transient_error()
or exc.api_error_subcode() == FACEBOOK_UNKNOWN_ERROR_CODE
or call_rate_limit_error
or call_connection_reset_error
)
return True

return backoff.on_exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from facebook_business import FacebookAdsApi, FacebookSession
from facebook_business.exceptions import FacebookRequestError
from source_facebook_marketing.api import API
from source_facebook_marketing.streams import AdCreatives, Campaigns
from source_facebook_marketing.streams import AdCreatives, AdsInsights, Campaigns

FB_API_VERSION = FacebookAdsApi.API_VERSION

Expand Down Expand Up @@ -154,3 +154,14 @@ def test_server_error(self, requests_mock, api, account_id):
with pytest.raises(FacebookRequestError):
stream = Campaigns(api=api, start_date=datetime.now(), end_date=datetime.now(), include_deleted=False)
list(stream.read_records(sync_mode=SyncMode.full_refresh, stream_state={}))

def test_connection_reset_error(self, requests_mock, api, account_id):
"""Error once, check that we retry and not fail"""

responses = [{"json": {"error": {"code": 104}}}]

requests_mock.register_uri("POST", FacebookSession.GRAPH + f"/{FB_API_VERSION}/act_{account_id}/insights", responses)

with pytest.raises(FacebookRequestError):
stream = AdsInsights(api=api, start_date=datetime.now(), end_date=datetime.now(), buffer_days=28, days_per_job=7)
list(stream.stream_slices(stream_state={}))
3 changes: 2 additions & 1 deletion docs/integrations/sources/facebook-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ As a summary, custom insights allows to replicate only some fields, resulting in

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.33 | 2021-12-28 | [10180](https://github.com/airbytehq/airbyte/pull/10180) | Add AdAccount and Images streams |
| 0.2.34 | 2022-02-15 | [10348](https://github.com/airbytehq/airbyte/pull/10348) | Add 104 error code to backoff triggers |
| 0.2.33 | 2022-02-09 | [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. |
| 0.2.31 | 2021-12-29 | [9138](https://github.com/airbytehq/airbyte/pull/9138) | Fix videos stream format field incorrect type |
| 0.2.30 | 2021-12-20 | [8962](https://github.com/airbytehq/airbyte/pull/8962) | Add `asset_feed_spec` field to `ad creatives` stream |
Expand Down