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: reduce start date by one day #27483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
92b7e1f
Connector health: source hubspot, gitlab, snapchat-marketing: fix builds
davydov-d May 10, 2023
01ee45e
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 10, 2023
4ae17ec
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 12, 2023
3fadfe3
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 12, 2023
a51c998
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 15, 2023
afd1fae
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 16, 2023
72efed0
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 17, 2023
db47568
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 17, 2023
7880cf0
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 19, 2023
d1d08dc
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 19, 2023
5e731f7
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 22, 2023
a8780f9
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 23, 2023
cac6c95
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 24, 2023
c772743
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 24, 2023
ebf235c
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 24, 2023
313db7d
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 25, 2023
779dfee
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 26, 2023
92995de
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 26, 2023
986f29e
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 29, 2023
2705474
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 30, 2023
265a5b4
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 30, 2023
2e9ed46
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d May 31, 2023
6711afb
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 1, 2023
79fe56b
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 1, 2023
e7b4177
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 1, 2023
a8968c4
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 2, 2023
9f0b93e
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 6, 2023
1eb1cb2
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 8, 2023
3d6b33b
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 8, 2023
4532c19
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 8, 2023
f3b6a62
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 9, 2023
b80f81e
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 12, 2023
dfa3579
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 12, 2023
7686f0c
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 13, 2023
2f4783a
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 14, 2023
6537212
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 15, 2023
b491aed
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 15, 2023
9d8e6ba
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 15, 2023
504cbb6
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 16, 2023
c4d1fd2
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 16, 2023
54923f8
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 16, 2023
5e9374b
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 16, 2023
b7ffd11
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 19, 2023
77d5b1a
Merge branch 'master' of github.com:airbytehq/airbyte
davydov-d Jun 19, 2023
ec759bf
#1975 source fb marketing: reduce start date by one day
davydov-d Jun 19, 2023
86a4c25
source fb marketing: upd changelog
davydov-d Jun 19, 2023
16c8a58
🤖 Auto format source-facebook-marketing code [skip ci]
octavia-squidington-iii Jun 19, 2023
b6d5f1a
format code
davydov-d Jun 19, 2023
c37f21c
Merge branch 'ddavydov/#1975-source-fb-reduce-start-date-by-one-day' …
davydov-d Jun 19, 2023
7a1c77b
#1975 source fb marketing: remove cloud version override
davydov-d Jun 21, 2023
d9e996d
Merge branch 'master' into ddavydov/#1975-source-fb-reduce-start-date…
davydov-d Jun 21, 2023
66ff199
Merge branch 'master' into ddavydov/#1975-source-fb-reduce-start-date…
davydov-d Jun 21, 2023
0e0add5
Merge branch 'master' into ddavydov/#1975-source-fb-reduce-start-date…
alafanechere Jun 21, 2023
d86437b
source facebook marketing: update CAT config
davydov-d Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]


LABEL io.airbyte.version=0.4.2
LABEL io.airbyte.version=0.4.3
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ acceptance_tests:
spec:
tests:
- spec_path: "integration_tests/spec.json"
backward_compatibility_tests_config:
disable_for_version: 0.3.6 # pattern for Account ID was added
connection:
tests:
- config_path: "secrets/config.json"
Expand Down Expand Up @@ -86,3 +84,7 @@ acceptance_tests:
tests:
- config_path: "secrets/config.json"
timeout_seconds: 4800
ignored_fields:
activities:
- name: extra_data
bypass_reason: "image_url in extra_data is changing frequently"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
dockerImageTag: 0.4.2
dockerImageTag: 0.4.3
dockerRepository: airbyte/source-facebook-marketing
githubIssueLabel: source-facebook-marketing
icon: facebook.svg
Expand All @@ -14,7 +14,6 @@ data:
registries:
cloud:
enabled: true
dockerImageTag: 0.4.2
oss:
enabled: true
releaseStage: generally_available
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from facebook_business import api

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from facebook_business.api import FacebookAdsApi, FacebookAdsApiBatch, FacebookBadObjectError, FacebookResponse
from source_facebook_marketing.streams.common import retry_pattern

from ..utils import validate_start_date

logger = logging.getLogger("airbyte")


Expand Down Expand Up @@ -189,7 +191,6 @@ class InsightAsyncJob(AsyncJob):

job_timeout = pendulum.duration(hours=1)
page_size = 100
INSIGHTS_RETENTION_PERIOD = pendulum.duration(months=37)

def __init__(self, edge_object: Union[AdAccount, Campaign, AdSet, Ad], params: Mapping[str, Any], **kwargs):
"""Initialize
Expand Down Expand Up @@ -242,10 +243,9 @@ def _split_by_edge_class(self, edge_class: Union[Type[Campaign], Type[AdSet], Ty
params = dict(copy.deepcopy(self._params))
# get objects from attribution window as well (28 day + 1 current day)
new_start = self._interval.start - pendulum.duration(days=28 + 1)
oldest_date = pendulum.today().date() - self.INSIGHTS_RETENTION_PERIOD
new_start = max(new_start, oldest_date)
params.update(fields=[pk_name], level=level)
new_start = validate_start_date(new_start)
params["time_range"].update(since=new_start.to_date_string())
params.update(fields=[pk_name], level=level)
params.pop("time_increment") # query all days
result = self._edge_object.get_insights(params=params)
ids = set(row[pk_name] for row in result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#

import logging
from typing import Union

import pendulum
from pendulum import DateTime
from pendulum import Date, DateTime

logger = logging.getLogger("airbyte")

Expand All @@ -14,32 +15,45 @@
# HTTP response.
# https://developers.facebook.com/docs/marketing-api/reference/ad-account/insights/#overview
DATA_RETENTION_PERIOD = 37
DateOrDateTime = Union[Date, DateTime]


def validate_start_date(start_date: DateTime) -> DateTime:
now = pendulum.now(tz=start_date.tzinfo)
today = now.replace(microsecond=0, second=0, minute=0, hour=0)
def cast_to_type(input_date: DateOrDateTime, target_date: DateOrDateTime) -> DateOrDateTime:
# casts `target_date` to the type of `input_date`
if type(target_date) == type(input_date):
return target_date
if isinstance(target_date, DateTime):
return target_date.date()
return pendulum.datetime(target_date.year, target_date.month, target_date.day)


def validate_start_date(start_date: DateOrDateTime) -> DateOrDateTime:
today = cast_to_type(start_date, pendulum.today())
retention_date = today.subtract(months=DATA_RETENTION_PERIOD)
if retention_date.day != today.day:
# `.subtract(months=37)` can be erroneous, for instance:
# 2023-03-31 - 37 month = 2020-02-29 which is incorrect, should be 2020-03-01
# that's why we're adjusting the date to the 1st day of the next month
retention_date = retention_date.replace(month=retention_date.month + 1, day=1)

if start_date > now:
# FB does not provide precise description of how we should calculate the 37 months datetime difference.
# As timezone difference can result in an additional time delta, this is a reassurance we stay inside the 37 months limit.
retention_date = retention_date.add(days=1)

if start_date > today:
message = f"The start date cannot be in the future. Set start date to today's date - {today}."
logger.warning(message)
return today
return cast_to_type(start_date, today)
elif start_date < retention_date:
message = (
f"The start date cannot be beyond {DATA_RETENTION_PERIOD} months from the current date. Set start date to {retention_date}."
)
logger.warning(message)
return retention_date
return cast_to_type(start_date, retention_date)
return start_date


def validate_end_date(start_date: DateTime, end_date: DateTime) -> DateTime:
def validate_end_date(start_date: DateOrDateTime, end_date: DateOrDateTime) -> DateOrDateTime:
if start_date > end_date:
message = f"The end date must be after start date. Set end date to {start_date}."
logger.warning(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ def test_split_job(self, mocker, api, edge_class, next_edge_class, id_field):
"breakdowns": [],
"fields": [id_field],
"level": next_edge_class.__name__.lower(),
"time_range": {"since": (today - pendulum.duration(months=37)).to_date_string(), "until": end.to_date_string()},
"time_range": {
"since": (today - pendulum.duration(months=37) + pendulum.duration(days=1)).to_date_string(),
"until": end.to_date_string()
},
}
)
assert len(small_jobs) == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
(
"start_date",
pendulum.local(2019, 1, 1),
pendulum.local(2020, 3, 1),
pendulum.local(2020, 3, 2),
[
f"The start date cannot be beyond 37 months from the current date. "
f"Set start date to {pendulum.local(2020, 3, 1)}."
f"Set start date to {pendulum.local(2020, 3, 2)}."
]
),
(
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 @@ -165,8 +165,9 @@ Please be informed that the connector uses the `lookback_window` parameter to pe

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.4.2 | 2023-06-09 | [27201](https://github.com/airbytehq/airbyte/pull/27201) | Add `complete_oauth_server_output_specification` to spec |
| 0.4.1 | 2023-06-02 | [26941](https://github.com/airbytehq/airbyte/pull/26941) | Remove `authSpecification` from spec.json, use `advanced_auth` instead |
| 0.4.3 | 2023-05-12 | [27483](https://github.com/airbytehq/airbyte/pull/27483) | Reduce replication start date by one more day |
| 0.4.2 | 2023-06-09 | [27201](https://github.com/airbytehq/airbyte/pull/27201) | Add `complete_oauth_server_output_specification` to spec |
| 0.4.1 | 2023-06-02 | [26941](https://github.com/airbytehq/airbyte/pull/26941) | Remove `authSpecification` from spec.json, use `advanced_auth` instead |
| 0.4.0 | 2023-05-29 | [26720](https://github.com/airbytehq/airbyte/pull/26720) | Add Prebuilt Ad Insights reports |
| 0.3.7 | 2023-05-12 | [26000](https://github.com/airbytehq/airbyte/pull/26000) | Handle config errors |
| 0.3.6 | 2023-04-27 | [22999](https://github.com/airbytehq/airbyte/pull/22999) | Specified date formatting in specification |
Expand Down