Skip to content

Commit

Permalink
Fix update_cached_state typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed May 23, 2024
1 parent e1160c5 commit 68f5bd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions posthog/caching/calculate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion posthog/caching/insight_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down

0 comments on commit 68f5bd6

Please sign in to comment.