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(workflows): don't gate AWS reputation reads on static SES keys (#75973)

Meikel Ratz8b979f5d2561
diff --git a/products/workflows/backend/api/hog_flow.py b/products/workflows/backend/api/hog_flow.py
index 212278e97833..f52870ba2344 100644
--- a/products/workflows/backend/api/hog_flow.py
+++ b/products/workflows/backend/api/hog_flow.py
@@ -7,7 +7,6 @@ from copy import deepcopy
from datetime import timedelta
from typing import Any, Optional, cast
-from django.conf import settings
from django.core.cache import cache
from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.signing import BadSignature, SignatureExpired, TimestampSigner
@@ -1297,6 +1296,9 @@ def _email_sending_rates(sent: int, bounced: int, complained: int) -> dict[str,
AWS_TENANT_REPUTATION_CACHE_SECONDS = 5 * 60
+# Failures cache too, but far shorter than successes: long enough that an unreachable SES isn't
+# re-dialled on every request, short enough that a just-fixed config recovers within a minute.
+AWS_TENANT_REPUTATION_ERROR_CACHE_SECONDS = 60
def _aws_tenant_health(sending_status: str, reputation_impact: str | None) -> str:
@@ -1314,10 +1316,12 @@ def _fetch_aws_tenant_reputation(team_id: int) -> dict[str, Any] | None:
AWS-side tenant state for the reputation endpoint, cached briefly: the endpoint reloads on every
search keystroke and three SES API round-trips per keystroke would be slow and rate-limited.
Failures return None (the response field is nullable) so AWS being unreachable never breaks the
- rates display; errors aren't cached, so the next request retries.
+ rates display; failures cache under a shorter TTL so a broken SES isn't re-dialled per request.
+
+ Deliberately no SES_ACCESS_KEY_ID gate: cloud pods authenticate via their IAM role and leave
+ the key env vars unset, so a key check reads as "SES not configured" exactly where SES IS
+ configured. Environments truly without SES fail the call and land in the error path below.
"""
- if not settings.SES_ACCESS_KEY_ID:
- return None
cache_key = f"workflows_ses_tenant_reputation_{team_id}"
cached = cache.get(cache_key)
if cached is not None:
@@ -1326,6 +1330,7 @@ def _fetch_aws_tenant_reputation(team_id: int) -> dict[str, Any] | None:
raw = SESProvider().get_tenant_reputation(team_id)
except Exception:
logger.exception("Failed to fetch SES tenant reputation", team_id=team_id)
+ cache.set(cache_key, {"value": None}, AWS_TENANT_REPUTATION_ERROR_CACHE_SECONDS)
return None
value = (
{
diff --git a/products/workflows/backend/api/test/test_email_reputation.py b/products/workflows/backend/api/test/test_email_reputation.py
index 42004abbb089..7bce28dfb1c0 100644
--- a/products/workflows/backend/api/test/test_email_reputation.py
+++ b/products/workflows/backend/api/test/test_email_reputation.py
@@ -118,6 +118,21 @@ class TestEmailReputationAPI(APIBaseTest):
assert data["aws"] is None
assert data["workflows"] == []
+ def test_reputation_endpoint_does_not_redial_aws_after_a_failure(self):
+ provider = MagicMock()
+ provider.get_tenant_reputation.side_effect = Exception("SES timeout")
+ with (
+ patch("products.workflows.backend.api.hog_flow.fetch_app_metric_totals_by_source", return_value={}),
+ patch("products.workflows.backend.api.hog_flow.SESProvider", return_value=provider),
+ ):
+ url = f"/api/projects/{self.team.id}/hog_flows/reputation"
+ first = self.client.get(url)
+ second = self.client.get(url)
+
+ assert first.json()["aws"] is None
+ assert second.json()["aws"] is None
+ assert provider.get_tenant_reputation.call_count == 1
+
# Creating a HogFlowBatchJob fires a post_save signal that dispatches to the plugin server —
# patched out like every other batch-job test, or CI fails on the outbound HTTP attempt.
@patch(