Skip to content

: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.

fix(messaging): import customer.io suppressions before global unsubscribes (#124104)

Harley Alexandere1f42139c7ce
diff --git a/products/messaging/backend/services/customerio_import_service.py b/products/messaging/backend/services/customerio_import_service.py
index 20fcafbba4bd..d727a9940bed 100644
--- a/products/messaging/backend/services/customerio_import_service.py
+++ b/products/messaging/backend/services/customerio_import_service.py
@@ -84,12 +84,14 @@ class CustomerIOImportService:
self.progress["topics_found"] = len(topics)
self._import_categories(topics)
- # Step 3: Process globally unsubscribed users
- self._process_globally_unsubscribed_users()
-
- # Step 4: Import addresses Customer.io's email provider suppressed
+ # Step 3: Import addresses Customer.io's email provider suppressed. They go before the global
+ # unsubscribes because those can run to hundreds of pages, past the request timeout, and each page
+ # saves on its own, so the shorter suppression lists finish first.
self._import_suppressions()
+ # Step 4: Process globally unsubscribed users
+ self._process_globally_unsubscribed_users()
+
self.progress["status"] = "completed"
except Exception as e:
diff --git a/products/messaging/backend/services/test_customerio_import_service.py b/products/messaging/backend/services/test_customerio_import_service.py
index f0cf9b76c080..85ef2c497cf2 100644
--- a/products/messaging/backend/services/test_customerio_import_service.py
+++ b/products/messaging/backend/services/test_customerio_import_service.py
@@ -340,6 +340,27 @@ [email protected],cio_6,"{""topics"": {""topic_1"": true, ""topic_2"": true}}"
"[email protected]": (SuppressionSource.BOUNCE, False, True),
}
+ @patch("products.messaging.backend.services.customerio_import_service.SUPPRESSION_PAGE_DELAY_SECONDS", 0)
+ @patch("products.messaging.backend.services.customerio_import_service.CustomerIOClient")
+ def test_api_import_saves_suppressions_before_a_killed_unsubscribe_step(self, mock_client_class: MagicMock) -> None:
+ class RequestKilled(BaseException):
+ pass
+
+ mock_client = mock_client_class.return_value
+ mock_client.validate_credentials.return_value = True
+ mock_client.get_subscription_topics.return_value = []
+ mock_client.get_suppressions.side_effect = lambda suppression_type, limit, offset: (
+ [{"email": "[email protected]"}] if (suppression_type, offset) == ("bounces", 0) else []
+ )
+ mock_client.get_globally_unsubscribed_customers.side_effect = RequestKilled()
+
+ with self.assertRaises(RequestKilled):
+ CustomerIOImportService(self.team.id, self.api_key, self.user.id).import_api_data()
+
+ assert list(MessageSuppression.objects.for_team(self.team.id).values_list("identifier", flat=True)) == [
+ ]
+
def test_process_csv_without_categories(self):
"""Test CSV processing when no categories exist"""
csv_content = """email,id,cio_subscription_preferences