From 35e2cb26e006d0435c67333adbe1b978fbc8d5ff Mon Sep 17 00:00:00 2001 From: Alexander Spicer Date: Thu, 20 Jun 2024 16:53:43 -0700 Subject: [PATCH] fix bug --- posthog/hogql_queries/actors_query_runner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/posthog/hogql_queries/actors_query_runner.py b/posthog/hogql_queries/actors_query_runner.py index 1d0406461b53c..1f033b07bd2b1 100644 --- a/posthog/hogql_queries/actors_query_runner.py +++ b/posthog/hogql_queries/actors_query_runner.py @@ -232,6 +232,7 @@ def to_query(self) -> ast.SelectQuery: order_by = [] with self.timings.measure("select"): + ctes = {} if not self.query.source: join_expr = ast.JoinExpr(table=ast.Field(chain=[self.strategy.origin])) else: @@ -264,9 +265,8 @@ def to_query(self) -> ast.SelectQuery: ), ) - ctes = { - source_alias: ast.CTE(name=source_alias, expr=source_query, cte_type="subquery"), - } + ctes[source_alias] = ast.CTE(name=source_alias, expr=source_query, cte_type="subquery") + # For now, only use this CTE optimization in Trends, until we test it with other queries if isinstance(self.strategy, PersonStrategy) and any( isinstance(x, C) for x in [getattr(self.query.source, "source", None)] for C in (TrendsQuery,)