:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(warehouse_sources): support LinkedIn Ads API version 202608 (#86336)
Tom Owerse37d6c97e557
diff --git a/products/warehouse_sources/backend/migrations/0151_repin_linkedin_ads_api_version.py b/products/warehouse_sources/backend/migrations/0151_repin_linkedin_ads_api_version.pynew file mode 100644index 000000000000..b02449a3bc3b--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0151_repin_linkedin_ads_api_version.py@@ -0,0 +1,33 @@+from django.db import migrations++# LinkedIn's 202606 monthly version is deprecated and sunsets 2027-06-15 (a 426 `NONEXISTENT_VERSION`+# thereafter). Repin source-level pins onto the current 202608 version. 202608's changes are additive+# for the endpoints/fields this source reads (ad accounts, campaigns, campaign groups, creatives,+# conversions, ad analytics), so the repin needs no data/schema transform — only the pin moves.+LINKEDIN_ADS_SOURCE_TYPE = "LinkedinAds"+DEPRECATED_VERSION = "202606"+TARGET_VERSION = "202608"+++def repin_linkedin_ads_api_version(apps, schema_editor):+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")++ # Only touch source-level pins still on the deprecated version. NULL pins already resolve to the+ # source's `default_version` (now 202608), so they need no update. Filtering on the exact old value+ # keeps this idempotent — a re-run matches nothing. Schema-level overrides+ # (`ExternalDataSchema.api_version`) are intentionally customer-pinned and are left untouched.+ ExternalDataSource.objects.filter(source_type=LINKEDIN_ADS_SOURCE_TYPE, api_version=DEPRECATED_VERSION).update(+ api_version=TARGET_VERSION+ )+++class Migration(migrations.Migration):+ dependencies = [+ ("warehouse_sources", "0150_repin_bloomerang_api_version"),+ ]++ operations = [+ # Reverse is a no-op: once repinned, a source on 202608 is indistinguishable from one natively+ # created on the new default, so downgrading every 202608 row would clobber legitimate native pins.+ migrations.RunPython(repin_linkedin_ads_api_version, migrations.RunPython.noop, elidable=True),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 3f6d952a782f..8d8d20cb4615 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0150_repin_bloomerang_api_version+0151_repin_linkedin_ads_api_versiondiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.pyindex 194edc7bf310..51225edd1520 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py@@ -52,6 +52,7 @@ from .linkedin_ads import (# LinkedIn's Marketing API uses monthly date-based versioning (YYYYMM) sent as a request header.LINKEDIN_ADS_VERSION_202606 = "202606"LINKEDIN_ADS_VERSION_202607 = "202607"+LINKEDIN_ADS_VERSION_202608 = "202608"# Opaque source version label -> LinkedIn API version header. The legacy `v1` pin keeps sending the# header it always has (`API_VERSION`), so existing syncs are byte-for-byte unchanged.@@ -59,6 +60,7 @@ _API_HEADER_BY_VERSION = {UNVERSIONED_API_VERSION: API_VERSION,LINKEDIN_ADS_VERSION_202606: LINKEDIN_ADS_VERSION_202606,LINKEDIN_ADS_VERSION_202607: LINKEDIN_ADS_VERSION_202607,+ LINKEDIN_ADS_VERSION_202608: LINKEDIN_ADS_VERSION_202608,}@@ -66,12 +68,21 @@ _API_HEADER_BY_VERSION = {class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResumeConfig], OAuthMixin):api_docs_url = "https://learn.microsoft.com/en-us/linkedin/marketing/versioning"- supported_versions = (UNVERSIONED_API_VERSION, LINKEDIN_ADS_VERSION_202606, LINKEDIN_ADS_VERSION_202607)- default_version = LINKEDIN_ADS_VERSION_202607+ supported_versions = (+ UNVERSIONED_API_VERSION,+ LINKEDIN_ADS_VERSION_202606,+ LINKEDIN_ADS_VERSION_202607,+ LINKEDIN_ADS_VERSION_202608,+ )+ default_version = LINKEDIN_ADS_VERSION_202608# LinkedIn supports each version for a minimum of one year, then starts rejecting it with a 426# `NONEXISTENT_VERSION` (see `get_non_retryable_errors`). The legacy `v1` pin sends the header it- # always has (202508, August 2025 — `_API_HEADER_BY_VERSION`), which reached that one-year mark.- deprecated_versions = (VersionDeprecation(version=UNVERSIONED_API_VERSION, sunset_at=date(2026, 8, 1)),)+ # always has (202508, August 2025 — `_API_HEADER_BY_VERSION`), which reached that one-year mark;+ # 202606 sunsets 2027-06-15. Repin migration lives alongside this bump.+ deprecated_versions = (+ VersionDeprecation(version=UNVERSIONED_API_VERSION, sunset_at=date(2026, 8, 1)),+ VersionDeprecation(version=LINKEDIN_ADS_VERSION_202606, sunset_at=date(2027, 6, 15)),+ )lists_tables_without_credentials = True # static endpoint catalog — safe for public docsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.pyindex 02ed0ca0cd45..2c486654a08b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py@@ -46,7 +46,7 @@ class TestLinkedinAdsClient:assert result == [{"id": "123", "name": "Test Account"}]mock_client_instance.finder.assert_called_once()- @pytest.mark.parametrize("api_version", ["202508", "202606", "202607"])+ @pytest.mark.parametrize("api_version", ["202508", "202606", "202607", "202608"])@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.client.RestliClient")def test_request_sends_configured_api_version(self, mock_restli_client, api_version):"""The configured version must reach the Restli `version_string`, else every request hitsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.pyindex acfa73253d7b..97544fd4d788 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py@@ -12,6 +12,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_afrom products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.source import (LINKEDIN_ADS_VERSION_202606,LINKEDIN_ADS_VERSION_202607,+ LINKEDIN_ADS_VERSION_202608,LinkedInAdsSource,)@@ -81,14 +82,24 @@ class TestLinkedInAdsSource:retryable_errors = self.source.get_retryable_errors()assert not any(pattern in other_error for pattern in retryable_errors)- def test_defaults_new_sources_to_202607(self):- assert self.source.default_version == LINKEDIN_ADS_VERSION_202607- assert set(self.source.supported_versions) == {"v1", LINKEDIN_ADS_VERSION_202606, LINKEDIN_ADS_VERSION_202607}-- def test_legacy_v1_pin_is_deprecated(self):- # "v1" backs the sunset 202508 header (see client.API_VERSION) — the in-product deprecation- # banner depends on this metadata staying declared.- assert self.source.deprecated_versions == (VersionDeprecation(version="v1", sunset_at=date(2026, 8, 1)),)+ def test_defaults_new_sources_to_202608(self):+ assert self.source.default_version == LINKEDIN_ADS_VERSION_202608+ assert set(self.source.supported_versions) == {+ "v1",+ LINKEDIN_ADS_VERSION_202606,+ LINKEDIN_ADS_VERSION_202607,+ LINKEDIN_ADS_VERSION_202608,+ }++ def test_deprecated_versions_carry_sunset_dates(self):+ # "v1" backs the sunset 202508 header (see client.API_VERSION); 202606 sunsets 2027-06-15.+ # The in-product deprecation banner depends on this metadata staying declared, and the default+ # (202608) must never appear here.+ assert self.source.deprecated_versions == (+ VersionDeprecation(version="v1", sunset_at=date(2026, 8, 1)),+ VersionDeprecation(version=LINKEDIN_ADS_VERSION_202606, sunset_at=date(2027, 6, 15)),+ )+ assert self.source.default_version not in {d.version for d in self.source.deprecated_versions}@pytest.mark.parametrize("pinned_version,expected_header",@@ -98,8 +109,9 @@ class TestLinkedInAdsSource:("v1", "202508"),(LINKEDIN_ADS_VERSION_202606, "202606"),(LINKEDIN_ADS_VERSION_202607, "202607"),+ (LINKEDIN_ADS_VERSION_202608, "202608"),# No pin resolves to the new default.- (None, "202607"),+ (None, "202608"),# An undeclared pin is honored verbatim and passed straight through for LinkedIn to validate.("209901", "209901"),],@@ -128,7 +140,7 @@ class TestLinkedInAdsSource:self.source.get_oauth_accounts(integration_id=456, team_id=self.team_id)- assert mock_client_for_integration.call_args.kwargs["api_version"] == "202607"+ assert mock_client_for_integration.call_args.kwargs["api_version"] == "202608"def test_demographic_breakdowns_are_offered_but_not_enabled_by_default(self):# These fan out to one row per day per demographic value on top of the performance tables,