From 3de112b3b07848777e01ce6101067032c219342f Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Thu, 19 Oct 2023 10:37:46 +0100 Subject: [PATCH] Make mypy happy --- posthog/models/insight.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/posthog/models/insight.py b/posthog/models/insight.py index 3e420e4a80c13b..6343a78bb6d3a6 100644 --- a/posthog/models/insight.py +++ b/posthog/models/insight.py @@ -181,13 +181,19 @@ class Meta: def generate_insight_cache_key(insight: Insight, dashboard: Optional[Dashboard]) -> str: try: if insight.query is not None: - from posthog.hogql_queries.apply_dashboard_filters import apply_dashboard_filters + dashboard_filters = dashboard.filters if dashboard else None + + if dashboard_filters: + from posthog.hogql_queries.apply_dashboard_filters import apply_dashboard_filters + + q = apply_dashboard_filters(insight.query, dashboard_filters, insight.team) + else: + q = insight.query - q = apply_dashboard_filters(insight.query, dashboard.filters, insight.team) if q.get("source"): q = q["source"] - return generate_cache_key("{}_{}_{}".format(q, dashboard.filters, insight.team_id)) + return generate_cache_key("{}_{}_{}".format(q, dashboard_filters, insight.team_id)) dashboard_insight_filter = get_filter(data=insight.dashboard_filters(dashboard=dashboard), team=insight.team) candidate_filters_hash = generate_cache_key("{}_{}".format(dashboard_insight_filter.toJSON(), insight.team_id))