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 DATA_RETENTION_PERIOD validation and schema data type failed_delivery_checks issues #15012

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.2.56
LABEL io.airbyte.version=0.2.57
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"cached_property==1.5.2",
"facebook_business==13.0.0",
"pendulum>=2,<3",
"python-dateutil==2.8.2",
lazebnyi marked this conversation as resolved.
Show resolved Hide resolved
]

TEST_REQUIREMENTS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@
"type": ["null", "number"]
},
"failed_delivery_checks": {
"type": ["null", "number"]
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"summary": {
"type": ["null", "string"]
},
"description": {
"type": ["null", "string"]
},
"check_name": {
"type": ["null", "string"]
}
}
}
},
"fb_entity": {
"type": ["null", "number"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
#

from datetime import datetime
from dateutil.relativedelta import relativedelta


class FutureDateException(Exception):
def __init__(self, field_name, *args, **kwargs):
self.field_name = field_name
self.message = f"{self.field_name} cannot be in the future. Please set today's date or later"
# Facebook store metrics maximum of 37 months old. Any time range that
# older that 37 months from current date would result in 400 Bad request
# HTTP response.
# https://developers.facebook.com/docs/marketing-api/reference/ad-account/insights/#overview
DATA_RETENTION_PERIOD = 37


class ValidationDateException(Exception):
def __init__(self, message, *args, **kwargs):
self.message = message
super().__init__(self.message, *args, **kwargs)

def __str__(self):
Expand All @@ -18,7 +25,11 @@ def __repr__(self):
return self.__str__()


def validate_date_field(field, date):
def validate_date_field(field_name, date):
if date.timestamp() > datetime.now().timestamp():
raise FutureDateException(field)
message = f"{field_name} cannot be in the future. Please set today's date or later."
raise ValidationDateException(message)
elif date.timestamp() < (datetime.now() + relativedelta(months=-DATA_RETENTION_PERIOD)).timestamp():
message = f"{field_name} cannot be beyond {DATA_RETENTION_PERIOD} months from the current date."
raise ValidationDateException(message)
lazebnyi marked this conversation as resolved.
Show resolved Hide resolved
return date
1 change: 1 addition & 0 deletions docs/integrations/sources/facebook-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Please be informed that the connector uses the `lookback_window` parameter to pe

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.2.57 | 2022-07-25 | [15012](https://github.com/airbytehq/airbyte/pull/15012) | Add `DATA_RETENTION_PERIOD`validation and fix `failed_delivery_checks` field schema type issue |
| 0.2.56 | 2022-07-19 | [14831](https://github.com/airbytehq/airbyte/pull/14831) | Add future `start_date` and `end_date` validation |
| 0.2.55 | 2022-07-18 | [14786](https://github.com/airbytehq/airbyte/pull/14786) | Check if the authorized user has the "MANAGE" task permission when getting the `funding_source_details` field in the ad\_account stream |
| 0.2.54 | 2022-06-29 | [14267](https://github.com/airbytehq/airbyte/pull/14267) | Make MAX_BATCH_SIZE available in config |
Expand Down