diff --git a/posthog/caching/calculate_results.py b/posthog/caching/calculate_results.py index c57c76fa26cf33..1af7b1faaa1a45 100644 --- a/posthog/caching/calculate_results.py +++ b/posthog/caching/calculate_results.py @@ -146,12 +146,16 @@ def calculate_for_query_based_insight( if isinstance(response, BaseModel): response = response.model_dump() - update_cached_state( # Updating the relevant InsightCachingState - insight.team_id, - response.get("cache_key"), - response.get("last_refresh"), - result=None, # Not caching the result here, since in HogQL this is the query runner's responsibility - ) + cache_key = response.get("cache_key") + last_refresh = response.get("last_refresh") + if isinstance(cache_key, str) and isinstance(last_refresh, str): + update_cached_state( # Updating the relevant InsightCachingState + insight.team_id, + cache_key, + last_refresh, + result=None, # Not caching the result here, since in HogQL this is the query runner's responsibility + ) + return InsightResult( # Translating `QueryResponse` to legacy insights shape # The response may not be conformant with that, hence these are all `.get()`s diff --git a/posthog/caching/insight_cache.py b/posthog/caching/insight_cache.py index d8989a9edb515b..12fc26d8fc5cdc 100644 --- a/posthog/caching/insight_cache.py +++ b/posthog/caching/insight_cache.py @@ -171,7 +171,7 @@ def update_cache(caching_state_id: UUID): def update_cached_state( team_id: int, cache_key: str, - timestamp: datetime, + timestamp: datetime | str, result: Any, ttl: Optional[int] = None, ):