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(ws): correct Meta Ads token refresh to prevent auth errors (#57615)

estefania36fc75240ac4
diff --git a/posthog/models/integration.py b/posthog/models/integration.py
index 8f9f78e9053d..d6839e90e1a0 100644
--- a/posthog/models/integration.py
+++ b/posthog/models/integration.py
@@ -2959,11 +2959,11 @@ class MetaAdsIntegration:
def refresh_access_token(self):
oauth_config = OauthIntegration.oauth_config_for_kind(self.integration.kind)
- # check if refresh is necessary (less than 7 days)
+ # skip refresh if more than 7 days until expiry
if self.integration.config.get("expires_in") and self.integration.config.get("refreshed_at"):
if (
time.time()
- > self.integration.config.get("refreshed_at") + self.integration.config.get("expires_in") - 604800
+ < self.integration.config.get("refreshed_at") + self.integration.config.get("expires_in") - 604800
):
return
diff --git a/posthog/tasks/integrations.py b/posthog/tasks/integrations.py
index 3373a21a7a4b..df3a1980ed2b 100644
--- a/posthog/tasks/integrations.py
+++ b/posthog/tasks/integrations.py
@@ -14,7 +14,7 @@ def refresh_integrations() -> int:
from posthog.models.integration import Integration, OauthIntegration
oauth_integrations = defer_repository_cache_fields(
- Integration.objects.filter(kind__in=OauthIntegration.supported_kinds).all()
+ Integration.objects.filter(kind__in=OauthIntegration.supported_kinds).exclude(kind="meta-ads").all()
)
for integration in oauth_integrations: