From e12e0315198d5895e9c73160a0904f54391da11b Mon Sep 17 00:00:00 2001 From: xacadil <92389481+xacadil@users.noreply.github.com> Date: Wed, 6 Dec 2023 23:56:09 +0500 Subject: [PATCH] Fix to automatically add deals_association_parent stream if it is missing in the catalog (#16) --- tap_hubspot_beta/client_base.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tap_hubspot_beta/client_base.py b/tap_hubspot_beta/client_base.py index d64411a..81f6fd6 100644 --- a/tap_hubspot_beta/client_base.py +++ b/tap_hubspot_beta/client_base.py @@ -11,6 +11,8 @@ from singer_sdk.exceptions import FatalAPIError, RetriableAPIError from singer_sdk.streams import RESTStream from urllib3.exceptions import ProtocolError +from singer_sdk.mapper import SameRecordTransform, StreamMap +from singer_sdk.helpers._flattening import get_flattening_options from pendulum import parse @@ -262,6 +264,42 @@ def request_decorator(self, func): on_backoff=self.backoff_handler, )(func) return decorator + + @property + def stream_maps(self) -> List[StreamMap]: + """Get stream transformation maps. + + The 0th item is the primary stream map. List should not be empty. + + Returns: + A list of one or more map transformations for this stream. + """ + if self._stream_maps: + return self._stream_maps + + if self._tap.mapper: + #Append deals association stream if it is not in the catalog. + if self.name == "deals_association_parent" and self.name not in self._tap.mapper.stream_maps: + self._tap.mapper.stream_maps.update({"deals_association_parent":self._tap.mapper.stream_maps["deals"]}) + self._tap.mapper.stream_maps["deals_association_parent"][0].stream_alias = "deals_association_parent" + self._stream_maps = self._tap.mapper.stream_maps[self.name] + self.logger.info( + f"Tap has custom mapper. Using {len(self.stream_maps)} provided map(s)." + ) + else: + self.logger.info( + f"No custom mapper provided for '{self.name}'. " + "Using SameRecordTransform." + ) + self._stream_maps = [ + SameRecordTransform( + stream_alias=self.name, + raw_schema=self.schema, + key_properties=self.primary_keys, + flattening_options=get_flattening_options(self.config), + ) + ] + return self._stream_maps class hubspotStreamSchema(hubspotStream):