From 6e008d5ef9d828d4e62e679d898f54d87341dee7 Mon Sep 17 00:00:00 2001 From: Eugene Kulak Date: Tue, 22 Feb 2022 18:45:03 +0400 Subject: [PATCH] fix custom insights --- .../source_facebook_marketing/source.py | 20 ++++++++++++------- .../source_facebook_marketing/spec.py | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/source.py b/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/source.py index 232749aaa6c4f..9183ef9cbc9b8 100644 --- a/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/source.py +++ b/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/source.py @@ -10,7 +10,7 @@ from airbyte_cdk.sources import AbstractSource from airbyte_cdk.sources.streams import Stream from source_facebook_marketing.api import API -from source_facebook_marketing.spec import ConnectorConfig +from source_facebook_marketing.spec import ConnectorConfig, InsightConfig from source_facebook_marketing.streams import ( AdAccount, AdCreatives, @@ -79,7 +79,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Type[Stream]]: Videos(api=api, start_date=config.start_date, end_date=config.end_date, include_deleted=config.include_deleted), ] - return self._update_insights_streams(insights=config.custom_insights, args=insights_args, streams=streams) + return self._update_insights_streams(insights=config.custom_insights, default_args=insights_args, streams=streams) def spec(self, *args, **kwargs) -> ConnectorSpecification: """Returns the spec for this integration. @@ -100,7 +100,7 @@ def spec(self, *args, **kwargs) -> ConnectorSpecification: ), ) - def _update_insights_streams(self, insights, args, streams) -> List[Type[Stream]]: + def _update_insights_streams(self, insights: List[InsightConfig], default_args, streams) -> List[Type[Stream]]: """Update method, if insights have values returns streams replacing the default insights streams else returns streams """ @@ -110,10 +110,16 @@ def _update_insights_streams(self, insights, args, streams) -> List[Type[Stream] insights_custom_streams = list() for insight in insights: - args["name"] = f"Custom{insight.name}" - args["fields"] = list(set(insight.fields)) - args["breakdowns"] = list(set(insight.breakdowns)) - args["action_breakdowns"] = list(set(insight.action_breakdowns)) + args = dict( + api=default_args["api"], + name=f"Custom{insight.name}", + fields=list(set(insight.fields)), + breakdowns=list(set(insight.breakdowns)), + action_breakdowns=list(set(insight.action_breakdowns)), + time_increment=insight.time_increment, + start_date=insight.start_date or default_args["start_date"], + end_date=insight.end_date or default_args["end_date"], + ) insight_stream = AdsInsights(**args) insights_custom_streams.append(insight_stream) diff --git a/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/spec.py b/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/spec.py index 5f2417f6b5bfb..542a8833f9a6e 100644 --- a/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/spec.py +++ b/airbyte-integrations/connectors/source-facebook-marketing/source_facebook_marketing/spec.py @@ -23,6 +23,9 @@ class InsightConfig(BaseModel): """Config for custom insights""" + class Config: + use_enum_values = True + name: str = Field( title="Name", description="The name value of insight",