Skip to content

Commit

Permalink
🐛 Source Hubspot: fix query string length for properties with history (
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-yermilov-gl committed Dec 15, 2023
1 parent 96ac32e commit 99ec45f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c
dockerImageTag: 2.0.0
dockerImageTag: 2.0.1
dockerRepository: airbyte/source-hubspot
documentationUrl: https://docs.airbyte.com/integrations/sources/hubspot
githubIssueLabel: source-hubspot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ def __bool__(self):
def as_url_param(self):
""""""

@property
@abc.abstractmethod
def as_url_param_with_history(self) -> str:
""""""

@property
@abc.abstractmethod
def _term_representation(self):
Expand Down Expand Up @@ -110,25 +105,27 @@ class APIv1Property(IURLPropertyRepresentation):
def as_url_param(self):
return {"property": self.properties}

def as_url_param_with_history(self) -> str:
return "&".join(map(lambda prop: f"propertiesWithHistory={prop}", self.properties))


class APIv2Property(IURLPropertyRepresentation):
_term_representation = "property={property}&"

def as_url_param(self):
return {"property": self.properties}

def as_url_param_with_history(self) -> str:
return "&".join(map(lambda prop: f"propertiesWithHistory={prop}", self.properties))


class APIv3Property(IURLPropertyRepresentation):
_term_representation = "{property},"

def as_url_param(self):
return {"properties": ",".join(self.properties)}

def as_url_param_with_history(self) -> str:
raise NotImplementedError("Not implemented")

class APIPropertiesWithHistory(IURLPropertyRepresentation):
"""
It works for both v1 and v2 versions of API
"""

_term_representation = "propertiesWithHistory={property}&"

def as_url_param(self):
return "&".join(map(lambda prop: f"propertiesWithHistory={prop}", self.properties))
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from source_hubspot.constants import OAUTH_CREDENTIALS, PRIVATE_APP_CREDENTIALS
from source_hubspot.errors import HubspotAccessDenied, HubspotInvalidAuth, HubspotRateLimited, HubspotTimeout, InvalidStartDateConfigError
from source_hubspot.helpers import (
APIPropertiesWithHistory,
APIv1Property,
APIv2Property,
APIv3Property,
Expand Down Expand Up @@ -1942,6 +1943,11 @@ def url(self):


class CompaniesPropertyHistory(PropertyHistory):
@cached_property
def _property_wrapper(self) -> IURLPropertyRepresentation:
properties = list(self.properties.keys())
return APIPropertiesWithHistory(properties=properties)

@property
def scopes(self) -> set:
return {"crm.objects.companies.read"}
Expand Down Expand Up @@ -2001,10 +2007,15 @@ def path(
next_page_token: Mapping[str, Any] = None,
properties: IURLPropertyRepresentation = None,
) -> str:
return f"{self.url}?{properties.as_url_param_with_history()}"
return f"{self.url}?{properties.as_url_param()}"


class DealsPropertyHistory(PropertyHistory):
@cached_property
def _property_wrapper(self) -> IURLPropertyRepresentation:
properties = list(self.properties.keys())
return APIPropertiesWithHistory(properties=properties)

@property
def scopes(self) -> set:
return {"crm.objects.deals.read"}
Expand Down Expand Up @@ -2064,7 +2075,7 @@ def path(
next_page_token: Mapping[str, Any] = None,
properties: IURLPropertyRepresentation = None,
) -> str:
return f"{self.url}?{properties.as_url_param_with_history()}"
return f"{self.url}?{properties.as_url_param()}"


class SubscriptionChanges(IncrementalStream):
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/hubspot.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ The connector is restricted by normal HubSpot [rate limitations](https://legacyd

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 2.0.1 | 2023-12-15 | [33527](https://github.com/airbytehq/airbyte/pull/33527) | Make query string calculated correctly for ProertyHistory streams to avoid 414 HTTP Errors |
| 2.0.0 | 2023-12-08 | [33266](https://github.com/airbytehq/airbyte/pull/33266) | Added ContactsPropertyHistory, CompaniesPropertyHistory, DealsPropertyHistory streams |
| 1.9.0 | 2023-12-04 | [33042](https://github.com/airbytehq/airbyte/pull/33042) | Added Web Analytics streams |
| 1.8.0 | 2023-11-23 | [32778](https://github.com/airbytehq/airbyte/pull/32778) | Extend `PropertyHistory` stream to support incremental sync |
Expand Down

0 comments on commit 99ec45f

Please sign in to comment.