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 Amazon Ads: fix Nonetype error when recordId is missing #28155

Merged
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 @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]


LABEL io.airbyte.version=2.3.0
LABEL io.airbyte.version=2.3.1
LABEL io.airbyte.name=airbyte/source-amazon-ads
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246
dockerImageTag: 2.3.0
dockerImageTag: 2.3.1
dockerRepository: airbyte/source-amazon-ads
githubIssueLabel: source-amazon-ads
icon: amazonads.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ def read_records(
profileId=report_info.profile_id,
recordType=report_info.record_type,
reportDate=report_date,
recordId=metric_object.get(self.metrics_type_to_id_map[report_info.record_type], str(uuid.uuid4())),
recordId=self.get_record_id(metric_object, report_info.record_type),
metric=metric_object,
).dict()

def get_record_id(self, metric_object: dict, record_type: str) -> str:
return metric_object.get(self.metrics_type_to_id_map[record_type]) or str(uuid.uuid4())

def backoff_max_time(func):
def wrapped(self, *args, **kwargs):
return backoff.on_exception(backoff.constant, RetryableException, max_time=self.report_wait_timeout * 60, interval=10)(func)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,25 @@ def test_brands_video_report_with_custom_record_types(config_gen, custom_record_
if record['recordType'] not in expected_record_types:
if flag_match_error:
assert False


@pytest.mark.parametrize(
"metric_object, record_type",
[
({"campaignId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"}, "campaigns"),
({"campaignId": ""}, "campaigns"),
({"campaignId": None}, "campaigns")
]
)
def test_get_record_id_by_report_type(config, metric_object, record_type):
"""
Test if a `recordId` is allways non-empty for any given `metric_object`.
`recordId` is not a contant key for every report.
We define suitable key for every report by its type and normally it should not be empty.
It may be `campaignId` or `adGroupId` or any other key depending on report type (See METRICS_TYPE_TO_ID_MAP).
In case when it is not defined or empty (sometimes we get one record with missing data while others are populated)
we must return `recordId` anyway so we generate it manually.
"""
profiles = make_profiles(profile_type="vendor")
stream = SponsoredProductsReportStream(config, profiles, authenticator=mock.MagicMock())
assert stream.get_record_id(metric_object, record_type), "recordId must be non-empty value"
3 changes: 2 additions & 1 deletion docs/integrations/sources/amazon-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ Information about expected report generation waiting time you may find [here](ht

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
| 2.3.0 | 2023-07-06 | [28002](https://github.com/airbytehq/airbyte/pull/28002) | Add sponsored_product_ad_group_suggested_keywords, sponsored_product_ad_group_bid_recommendations streams |
| 2.3.1 | 2023-07-11 | [28155](https://github.com/airbytehq/airbyte/pull/28155) | Bugfix: validation error when record values are missing |
| 2.3.0 | 2023-07-06 | [28002](https://github.com/airbytehq/airbyte/pull/28002) | Add sponsored_product_ad_group_suggested_keywords, sponsored_product_ad_group_bid_recommendations streams |
| 2.2.0 | 2023-07-05 | [27607](https://github.com/airbytehq/airbyte/pull/27607) | Add stream for sponsored brands v3 purchased product reports |
| 2.1.0 | 2023-06-19 | [25412](https://github.com/airbytehq/airbyte/pull/25412) | Add sponsored_product_campaign_negative_keywords, sponsored_display_budget_rules streams |
| 2.0.0 | 2023-05-31 | [25874](https://github.com/airbytehq/airbyte/pull/25874) | Type `portfolioId` as integer |
Expand Down
Loading