Skip to content

Commit

Permalink
Fix support for dashboard filters on insights with global filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Apr 25, 2024
1 parent 29b55e9 commit 5ac1bcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 7 additions & 6 deletions posthog/api/test/test_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,13 @@ def test_insight_refreshing_query(self, spy_execute_hogql_query) -> None:

#  Test property filter

dashboard = Dashboard.objects.get(pk=dashboard_id)
dashboard.filters = {
"properties": [{"key": "prop", "value": "val"}],
"date_from": "-14d",
}
dashboard.save()
Dashboard.objects.update(
id=dashboard_id,
filters={
"properties": [{"key": "prop", "value": "val"}],
"date_from": "-14d",
},
)
with freeze_time("2012-01-16T05:01:34.000Z"):
response = self.client.get(
f"/api/projects/{self.team.id}/insights/{insight_id}/?refresh=true&from_dashboard={dashboard_id}"
Expand Down
9 changes: 8 additions & 1 deletion posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
FunnelCorrelationQuery,
FunnelsActorsQuery,
PropertyGroupFilter,
PropertyGroupFilterValue,
TrendsQuery,
FunnelsQuery,
RetentionQuery,
Expand Down Expand Up @@ -429,7 +430,13 @@ def apply_dashboard_filters(self, dashboard_filter: DashboardFilter) -> Q:
if dashboard_filter.properties:
if self.query.properties:

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "HogQLQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "InsightActorsQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "FunnelsActorsQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "FunnelCorrelationQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "FunnelCorrelationActorsQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "InsightActorsQueryOptions" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 431 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "SessionsTimelineQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"
query_update["properties"] = PropertyGroupFilter(
type=FilterLogicalOperator.AND, values=[self.query.properties, dashboard_filter.properties]
type=FilterLogicalOperator.AND,
values=[
PropertyGroupFilterValue(type=FilterLogicalOperator.AND, values=self.query.properties),

Check failure on line 435 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "HogQLQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 435 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "InsightActorsQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"

Check failure on line 435 in posthog/hogql_queries/query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "FunnelsActorsQuery" of the upper bound "TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | ActorsQuery | EventsQuery | HogQLQuery | InsightActorsQuery | FunnelsActorsQuery | FunnelCorrelationQuery | FunnelCorrelationActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | WebOverviewQuery | WebStatsTableQuery | WebTopClicksQuery" of type variable "Q" has no attribute "properties"
PropertyGroupFilterValue(
type=FilterLogicalOperator.AND, values=dashboard_filter.properties
),
],
)
else:
query_update["properties"] = dashboard_filter.properties
Expand Down

0 comments on commit 5ac1bcf

Please sign in to comment.