Skip to content

Commit

Permalink
Source google-analytics-v4: fix pagination (#17943)
Browse files Browse the repository at this point in the history
* #787 oncall - source google-analytics: fix pagination

* source google-analytics-v4: upd changelog

* auto-bump connector version [ci skip]

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
davydov-d and octavia-squidington-iii authored Oct 13, 2022
1 parent 220513d commit 234089e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
- name: Google Analytics (Universal Analytics)
sourceDefinitionId: eff3616a-f9c3-11eb-9a03-0242ac130003
dockerRepository: airbyte/source-google-analytics-v4
dockerImageTag: 0.1.29
dockerImageTag: 0.1.30
documentationUrl: https://docs.airbyte.com/integrations/sources/google-analytics-universal-analytics
icon: google-analytics.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,7 @@
oauthFlowOutputParameters:
- - "access_token"
- - "refresh_token"
- dockerImage: "airbyte/source-google-analytics-v4:0.1.29"
- dockerImage: "airbyte/source-google-analytics-v4:0.1.30"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/google-analytics-universal-analytics"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY main.py ./
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.29
LABEL io.airbyte.version=0.1.30
LABEL io.airbyte.name=airbyte/source-google-analytics-v4
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ def path(self, **kwargs: Any) -> str:
return "./reports:batchGet"

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
next_page = response.json().get("nextPageToken")
if next_page:
return {"pageToken": next_page}
reports = response.json().get(self.report_field, [])
for report in reports:
# since we're requesting just one report at a time, the first report in the response is enough
next_page = report.get("nextPageToken")
if next_page:
return {"pageToken": next_page}

def should_retry(self, response: requests.Response) -> bool:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"values": ["3"]
}
]
},
"nextPageToken": "1"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"values": ["3"]
}
]
},
"nextPageToken": "1"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"values": ["3"]
}
]
},
"nextPageToken": "1"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,18 @@ def test_is_data_golden_flag_missing_equals_false(
for message in source.read(logging.getLogger(), test_config, configured_catalog):
if message.type == Type.RECORD:
assert message.record.data["isDataGolden"] is False


@pytest.mark.parametrize(
"configured_response, expected_token",
(
({}, None),
({"reports": []}, None),
({"reports": [{"data": {}, "columnHeader": {}}]}, None),
({"reports": [{"data": {}, "columnHeader": {}, "nextPageToken": 100000}]}, {"pageToken": 100000}),
),
)
def test_next_page_token(test_config, configured_response, expected_token):
response = MagicMock(json=MagicMock(return_value=configured_response))
token = GoogleAnalyticsV4Stream(test_config).next_page_token(response)
assert token == expected_token
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Incremental sync is supported only if you add `ga:date` dimension to your custom

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:---------------------------------------------------------------------------------------------|
| 0.1.30 | 2022-10-13 | [17943](https://github.com/airbytehq/airbyte/pull/17943) | Fix pagination |
| 0.1.29 | 2022-10-12 | [17905](https://github.com/airbytehq/airbyte/pull/17905) | Handle exceeded daily quota gracefully |
| 0.1.28 | 2022-09-24 | [16920](https://github.com/airbytehq/airbyte/pull/16920) | Added segments and filters to custom reports |
| 0.1.27 | 2022-10-07 | [17717](https://github.com/airbytehq/airbyte/pull/17717) | Improve CHECK by using `ga:hits` metric. |
Expand Down

0 comments on commit 234089e

Please sign in to comment.