Skip to content

Commit ca1cf9b

Browse files
authored
🐛 Source Facebook Marketing: Fix backoff trigger with ConnectionError (#10348)
* Add AdAccount and Images stream implementation * Update PR number * Updated docker version * Updated to linter * Update to review * Add comment to AdAccount read_records method * Bumped version in seed, definitions and specs files * Fix backoff errors code list * Deleted empty file * Updated to linter * Updated PR number * Added connection_reset_error to backoff * Fix unittest * Fix integration tests * Bumped seed version
1 parent e7d7c77 commit ca1cf9b

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
- name: Facebook Marketing
204204
sourceDefinitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
205205
dockerRepository: airbyte/source-facebook-marketing
206-
dockerImageTag: 0.2.34
206+
dockerImageTag: 0.2.35
207207
documentationUrl: https://docs.airbyte.io/integrations/sources/facebook-marketing
208208
icon: facebook.svg
209209
sourceType: api

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@
16481648
supportsNormalization: false
16491649
supportsDBT: false
16501650
supported_destination_sync_modes: []
1651-
- dockerImage: "airbyte/source-facebook-marketing:0.2.34"
1651+
- dockerImage: "airbyte/source-facebook-marketing:0.2.35"
16521652
spec:
16531653
documentationUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"
16541654
changelogUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"

airbyte-integrations/connectors/source-facebook-marketing/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.2.34
15+
LABEL io.airbyte.version=0.2.35
1616
LABEL io.airbyte.name=airbyte/source-facebook-marketing

airbyte-integrations/connectors/source-facebook-marketing/integration_tests/test_streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def state_with_include_deleted_fixture(state):
3333

3434
@pytest.fixture(scope="session", name="configured_catalog")
3535
def configured_catalog_fixture():
36-
return ConfiguredAirbyteCatalog.parse_file("integration_tests/configured_catalog.json")
36+
return ConfiguredAirbyteCatalog.parse_file("integration_tests/configured_catalog_without_insights.json")
3737

3838

3939
class TestFacebookMarketingSource:

airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/streams/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
FACEBOOK_RATE_LIMIT_ERROR_CODES = (4, 17, 32, 613, 80000, 80001, 80002, 80003, 80004, 80005, 80006, 80008)
1717
FACEBOOK_BATCH_ERROR_CODE = 960
1818
FACEBOOK_UNKNOWN_ERROR_CODE = 99
19+
FACEBOOK_CONNECTION_RESET_ERROR_CODE = 104
1920
DEFAULT_SLEEP_INTERVAL = pendulum.duration(minutes=1)
2021
MAX_BATCH_SIZE = 50
2122

@@ -37,7 +38,8 @@ def should_retry_api_error(exc):
3738
call_rate_limit_error = exc.api_error_code() in FACEBOOK_RATE_LIMIT_ERROR_CODES
3839
batch_timeout_error = exc.http_status() == http.client.BAD_REQUEST and exc.api_error_code() == FACEBOOK_BATCH_ERROR_CODE
3940
unknown_error = exc.api_error_subcode() == FACEBOOK_UNKNOWN_ERROR_CODE
40-
return any((exc.api_transient_error(), unknown_error, call_rate_limit_error, batch_timeout_error))
41+
connection_reset_error = exc.api_error_code() == FACEBOOK_CONNECTION_RESET_ERROR_CODE
42+
return any((exc.api_transient_error(), unknown_error, call_rate_limit_error, batch_timeout_error, connection_reset_error))
4143
return True
4244

4345
return backoff.on_exception(

airbyte-integrations/connectors/source-facebook-marketing/unit_tests/test_client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from facebook_business import FacebookAdsApi, FacebookSession
1212
from facebook_business.exceptions import FacebookRequestError
1313
from source_facebook_marketing.api import API
14-
from source_facebook_marketing.streams import AdCreatives, Campaigns
14+
from source_facebook_marketing.streams import AdCreatives, AdsInsights, Campaigns
1515

1616
FB_API_VERSION = FacebookAdsApi.API_VERSION
1717

@@ -159,3 +159,14 @@ def test_server_error(self, requests_mock, api, account_id):
159159
with pytest.raises(FacebookRequestError):
160160
stream = Campaigns(api=api, start_date=datetime.now(), end_date=datetime.now(), include_deleted=False)
161161
list(stream.read_records(sync_mode=SyncMode.full_refresh, stream_state={}))
162+
163+
def test_connection_reset_error(self, requests_mock, api, account_id):
164+
"""Error once, check that we retry and not fail"""
165+
166+
responses = [{"json": {"error": {"code": 104}}}]
167+
168+
requests_mock.register_uri("GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/act_{account_id}/insights", responses)
169+
170+
with pytest.raises(FacebookRequestError):
171+
stream = AdsInsights(api=api, start_date=datetime.now(), end_date=datetime.now())
172+
list(stream.stream_slices(stream_state={}, sync_mode=None))

docs/integrations/sources/facebook-marketing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ As a summary, custom insights allows to replicate only some fields, resulting in
103103

104104
| Version | Date | Pull Request | Subject |
105105
| :--- | :--- | :--- | :--- |
106+
| 0.2.35 | 2022-02-18 | [10348](https://github.com/airbytehq/airbyte/pull/10348) | Add 104 error code to backoff triggers |
106107
| 0.2.34 | 2022-02-17 | [10180](https://github.com/airbytehq/airbyte/pull/9805) | Performance and reliability fixes |
107108
| 0.2.33 | 2021-12-28 | [10180](https://github.com/airbytehq/airbyte/pull/10180) | Add AdAccount and Images streams |
108109
| 0.2.32 | 2022-01-07 | [10138](https://github.com/airbytehq/airbyte/pull/10138) | Add `primary_key` for all insights streams. |

0 commit comments

Comments
 (0)