Skip to content

🐛 Source Facebook Marketing: fix keyerror account_id #36689

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

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
dockerImageTag: 2.1.1
dockerImageTag: 2.1.2
dockerRepository: airbyte/source-facebook-marketing
documentationUrl: https://docs.airbyte.com/integrations/sources/facebook-marketing
githubIssueLabel: source-facebook-marketing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.1.1"
version = "2.1.2"
name = "source-facebook-marketing"
description = "Source implementation for Facebook Marketing."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def insights_job_timeout(self):
def list_objects(self, params: Mapping[str, Any]) -> Iterable:
"""Because insights has very different read_records we don't need this method anymore"""

def _add_account_id(self, record: dict[str, Any], account_id: str):
if "account_id" not in record:
record["account_id"] = account_id

def read_records(
self,
sync_mode: SyncMode,
Expand All @@ -131,6 +135,7 @@ def read_records(
for obj in job.get_result():
data = obj.export_all_data()
if self._response_data_is_valid(data):
self._add_account_id(data, account_id)
yield data
except FacebookBadObjectError as e:
raise AirbyteTracedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def test_read_records_all(self, mocker, api, some_config):
if read slice 2, 3, 1 state changed to 3
"""
job = mocker.Mock(spec=InsightAsyncJob)
job.get_result.return_value = [mocker.Mock(), mocker.Mock(), mocker.Mock()]
rec = mocker.Mock()
rec.export_all_data.return_value = {}
job.get_result.return_value = [rec, rec, rec]
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
stream = AdsInsights(
api=api,
Expand All @@ -124,8 +126,11 @@ def test_read_records_random_order(self, mocker, api, some_config):
2. if read slice 2, 3 state not changed
if read slice 2, 3, 1 state changed to 3
"""
rec = mocker.Mock()
rec.export_all_data.return_value = {}

job = mocker.Mock(spec=AsyncJob)
job.get_result.return_value = [mocker.Mock(), mocker.Mock(), mocker.Mock()]
job.get_result.return_value = [rec, rec, rec]
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
stream = AdsInsights(
api=api,
Expand All @@ -147,6 +152,38 @@ def test_read_records_random_order(self, mocker, api, some_config):

assert len(records) == 3

def test_read_records_add_account_id(self, mocker, api, some_config):
rec_without_account = mocker.Mock()
rec_without_account.export_all_data.return_value = {}

rec_with_account = mocker.Mock()
rec_with_account.export_all_data.return_value = {"account_id": "some_account_id"}

job = mocker.Mock(spec=AsyncJob)
job.get_result.return_value = [rec_without_account, rec_with_account]
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
stream = AdsInsights(
api=api,
account_ids=some_config["account_ids"],
start_date=datetime(2010, 1, 1),
end_date=datetime(2011, 1, 1),
insights_lookback_window=28,
)

records = list(
stream.read_records(
sync_mode=SyncMode.incremental,
stream_slice={
"insight_job": job,
"account_id": some_config["account_ids"][0],
},
)
)

assert len(records) == 2
for record in records:
assert record.get("account_id")

@pytest.mark.parametrize(
"state,result_state",
[
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/facebook-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ The Facebook Marketing connector uses the `lookback_window` parameter to repeate

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 2.1.2 | 2024-03-29 | [36689](https://github.com/airbytehq/airbyte/pull/36689) | Fix key error `account_id` for custom reports. |
| 2.1.1 | 2024-03-18 | [36025](https://github.com/airbytehq/airbyte/pull/36025) | Fix start_date selection behaviour |
| 2.1.0 | 2024-03-12 | [35978](https://github.com/airbytehq/airbyte/pull/35978) | Upgrade CDK to start emitting record counts with state and full refresh state |
| 2.0.1 | 2024-03-08 | [35913](https://github.com/airbytehq/airbyte/pull/35913) | Fix lookback window |
Expand Down
Loading