Skip to content

Commit ec4fe7b

Browse files
🐛 Source Facebook Marketing: fix keyerror account_id (#36689)
1 parent 2495c8d commit ec4fe7b

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

airbyte-integrations/connectors/source-facebook-marketing/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data:
1010
connectorSubtype: api
1111
connectorType: source
1212
definitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
13-
dockerImageTag: 2.1.1
13+
dockerImageTag: 2.1.2
1414
dockerRepository: airbyte/source-facebook-marketing
1515
documentationUrl: https://docs.airbyte.com/integrations/sources/facebook-marketing
1616
githubIssueLabel: source-facebook-marketing

airbyte-integrations/connectors/source-facebook-marketing/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
6-
version = "2.1.1"
6+
version = "2.1.2"
77
name = "source-facebook-marketing"
88
description = "Source implementation for Facebook Marketing."
99
authors = [ "Airbyte <[email protected]>",]

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

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def insights_job_timeout(self):
116116
def list_objects(self, params: Mapping[str, Any]) -> Iterable:
117117
"""Because insights has very different read_records we don't need this method anymore"""
118118

119+
def _add_account_id(self, record: dict[str, Any], account_id: str):
120+
if "account_id" not in record:
121+
record["account_id"] = account_id
122+
119123
def read_records(
120124
self,
121125
sync_mode: SyncMode,
@@ -131,6 +135,7 @@ def read_records(
131135
for obj in job.get_result():
132136
data = obj.export_all_data()
133137
if self._response_data_is_valid(data):
138+
self._add_account_id(data, account_id)
134139
yield data
135140
except FacebookBadObjectError as e:
136141
raise AirbyteTracedException(

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

+39-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def test_read_records_all(self, mocker, api, some_config):
9797
if read slice 2, 3, 1 state changed to 3
9898
"""
9999
job = mocker.Mock(spec=InsightAsyncJob)
100-
job.get_result.return_value = [mocker.Mock(), mocker.Mock(), mocker.Mock()]
100+
rec = mocker.Mock()
101+
rec.export_all_data.return_value = {}
102+
job.get_result.return_value = [rec, rec, rec]
101103
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
102104
stream = AdsInsights(
103105
api=api,
@@ -124,8 +126,11 @@ def test_read_records_random_order(self, mocker, api, some_config):
124126
2. if read slice 2, 3 state not changed
125127
if read slice 2, 3, 1 state changed to 3
126128
"""
129+
rec = mocker.Mock()
130+
rec.export_all_data.return_value = {}
131+
127132
job = mocker.Mock(spec=AsyncJob)
128-
job.get_result.return_value = [mocker.Mock(), mocker.Mock(), mocker.Mock()]
133+
job.get_result.return_value = [rec, rec, rec]
129134
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
130135
stream = AdsInsights(
131136
api=api,
@@ -147,6 +152,38 @@ def test_read_records_random_order(self, mocker, api, some_config):
147152

148153
assert len(records) == 3
149154

155+
def test_read_records_add_account_id(self, mocker, api, some_config):
156+
rec_without_account = mocker.Mock()
157+
rec_without_account.export_all_data.return_value = {}
158+
159+
rec_with_account = mocker.Mock()
160+
rec_with_account.export_all_data.return_value = {"account_id": "some_account_id"}
161+
162+
job = mocker.Mock(spec=AsyncJob)
163+
job.get_result.return_value = [rec_without_account, rec_with_account]
164+
job.interval = pendulum.Period(pendulum.date(2010, 1, 1), pendulum.date(2010, 1, 1))
165+
stream = AdsInsights(
166+
api=api,
167+
account_ids=some_config["account_ids"],
168+
start_date=datetime(2010, 1, 1),
169+
end_date=datetime(2011, 1, 1),
170+
insights_lookback_window=28,
171+
)
172+
173+
records = list(
174+
stream.read_records(
175+
sync_mode=SyncMode.incremental,
176+
stream_slice={
177+
"insight_job": job,
178+
"account_id": some_config["account_ids"][0],
179+
},
180+
)
181+
)
182+
183+
assert len(records) == 2
184+
for record in records:
185+
assert record.get("account_id")
186+
150187
@pytest.mark.parametrize(
151188
"state,result_state",
152189
[

docs/integrations/sources/facebook-marketing.md

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ The Facebook Marketing connector uses the `lookback_window` parameter to repeate
200200

201201
| Version | Date | Pull Request | Subject |
202202
|:--------|:-----------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
203+
| 2.1.2 | 2024-03-29 | [36689](https://github.com/airbytehq/airbyte/pull/36689) | Fix key error `account_id` for custom reports. |
203204
| 2.1.1 | 2024-03-18 | [36025](https://github.com/airbytehq/airbyte/pull/36025) | Fix start_date selection behaviour |
204205
| 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 |
205206
| 2.0.1 | 2024-03-08 | [35913](https://github.com/airbytehq/airbyte/pull/35913) | Fix lookback window |

0 commit comments

Comments
 (0)