Skip to content

🐛 Source Linkedin Ads: Fix issue where Accounts stream did not correctly handle provided account IDs #38013

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

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -11,7 +11,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 137ece28-5434-455c-8f34-69dc3782f451
dockerImageTag: 2.1.0
dockerImageTag: 2.1.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove dockerImageTag: 2.0.0 as issue is fixed now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

dockerRepository: airbyte/source-linkedin-ads
documentationUrl: https://docs.airbyte.com/integrations/sources/linkedin-ads
githubIssueLabel: source-linkedin-ads
Expand Down
184 changes: 91 additions & 93 deletions airbyte-integrations/connectors/source-linkedin-ads/poetry.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.1.0"
version = "2.1.1"
name = "source-linkedin-ads"
description = "Source implementation for Linkedin Ads."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from abc import ABC, abstractmethod
from typing import Any, Dict, Iterable, Mapping, MutableMapping, Optional
from urllib.parse import urlencode
from urllib.parse import quote, urlencode

import pendulum
import requests
Expand Down Expand Up @@ -183,12 +183,19 @@ def request_params(
Override request_params() to have the ability to accept the specific account_ids from user's configuration.
If we have list of account_ids, we need to make sure that the request_params are encoded correctly,
We will get HTTP Error 500, if we use standard requests.urlencode methods to parse parameters,
so the urlencode(..., safe=":(),") is used instead, to keep the values as they are.
so the urlencode(..., safe=":(),%") is used instead, to keep the values as they are.
"""
params = super().request_params(stream_state, stream_slice, next_page_token)
if self.accounts:
params["search"] = f"(id:(values:List({self.accounts})))"
return urlencode(params, safe="():,%")
# Construct the URN for each account ID
accounts = [f"urn:li:sponsoredAccount:{account_id}" for account_id in self.config.get("account_ids")]

# Join the URNs into a single string, separated by commas, and URL encode only this part
encoded_accounts = quote(",".join(accounts), safe=",")

# Insert the encoded account IDs into the overall structure, keeping colons and parentheses outside safe
params["search"] = f"(id:(values:List({encoded_accounts})))"
return urlencode(params, safe=":(),%")


class IncrementalLinkedinAdsStream(LinkedinAdsStream):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_next_page_token(self, requests_mock, response_json, expected):
assert expected == result

def test_request_params(self):
expected = "pageSize=500&q=search&search=(id:(values:List(1,2)))"
expected = "pageSize=500&q=search&search=(id:(values:List(urn%3Ali%3AsponsoredAccount%3A1,urn%3Ali%3AsponsoredAccount%3A2)))"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add test config with account ids for check in cat to prevent similar issue in future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the new config

result = self.stream.request_params(stream_state={}, stream_slice={"account_id": 123})
assert expected == result

Expand Down
3 changes: 2 additions & 1 deletion docs/integrations/sources/linkedin-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ After 5 unsuccessful attempts - the connector will stop the sync operation. In s

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
| 2.1.0 | 2024-04-30 | [37573](https://github.com/airbytehq/airbyte/pull/37573) | Update API version to `202404`; add cursor-based pagination |
| 2.1.1 | 2024-05-07 | [38013](https://github.com/airbytehq/airbyte/pull/38013) | Fix an issue where the `Accounts` stream did not correctly handle provided account IDs |
| 2.1.0 | 2024-04-30 | [37573](https://github.com/airbytehq/airbyte/pull/37573) | Update API version to `202404`; add cursor-based pagination |
| 2.0.0 | 2024-04-24 | [37531](https://github.com/airbytehq/airbyte/pull/37531) | Change primary key for Analytics Streams |
| 1.0.1 | 2024-03-28 | [34152](https://github.com/airbytehq/airbyte/pull/34152) | Proceed pagination if return less than expected |
| 1.0.0 | 2024-04-10 | [36927](https://github.com/airbytehq/airbyte/pull/36927) | Update primary key for Analytics Streams |
Expand Down
Loading