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: validate account ids #2163

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Videos,
)

from .utils import validate_end_date, validate_start_date
from .utils import validate_end_date, validate_start_date, validate_account_ids

logger = logging.getLogger("airbyte")
UNSUPPORTED_FIELDS = {"unique_conversions", "unique_ctr", "unique_clicks",
Expand Down Expand Up @@ -96,6 +96,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Type[Stream]]:

api = API(access_token=config.credentials.access_token)

validate_account_ids(api, config.account_ids)

insights_args = dict(
api=api, start_date=config.start_date, end_date=config.end_date, insights_lookback_window=config.insights_lookback_window, account_ids=config.account_ids,
)
Expand Down
16 changes: 16 additions & 0 deletions source-facebook-marketing/source_facebook_marketing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#

import logging
from typing import List

import pendulum
from pendulum import DateTime
from estuary_cdk.flow import ValidationError

from source_facebook_marketing.api import API, FacebookAPIException

logger = logging.getLogger("airbyte")

Expand Down Expand Up @@ -45,3 +49,15 @@ def validate_end_date(start_date: DateTime, end_date: DateTime) -> DateTime:
logger.warning(message)
return start_date
return end_date

def validate_account_ids(api: API, account_ids: List[str]):
errs = []
for account_id in account_ids:
try:
api._find_account(account_id)
except FacebookAPIException as err:
msg = f"Error when validating account ID {account_id}: {err}"
errs.append(msg)

if len(errs) > 0:
raise ValidationError(errs)
Loading