Skip to content

Commit

Permalink
fix(trends): Fixed trends breaking from rogue operator (#19777)
Browse files Browse the repository at this point in the history
Fixed trends breaking from rogue operator
  • Loading branch information
Gilbert09 authored Jan 16, 2024
1 parent 49d6ebe commit 242e8e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,53 @@ describe('filtersToQueryNode', () => {
}
expect(result).toEqual(query)
})

it('converts properties with the correct cohort structure', () => {
const properties: any = {
type: FilterLogicalOperator.And,
values: [
{
type: FilterLogicalOperator.And,
values: [
{
key: 'id',
type: PropertyFilterType.Cohort,
value: 6,
operator: null,
},
],
},
],
}

const filters: Partial<FilterType> = {
insight: InsightType.TRENDS,
properties,
}

const result = filtersToQueryNode(filters)

const query: InsightQueryNode = {
kind: NodeKind.TrendsQuery,
properties: {
type: FilterLogicalOperator.And,
values: [
{
type: FilterLogicalOperator.And,
values: [
{
key: 'id',
type: PropertyFilterType.Cohort,
value: 6,
},
],
},
],
},
series: [],
}
expect(result).toEqual(query)
})
})

describe('example insights', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ const cleanProperties = (parentProperties: FilterType['properties']): InsightsQu
}
}

// Some saved insights have `"operator": null` defined in the properties, this
// breaks HogQL trends and Pydantic validation
if (filter.type === PropertyFilterType.Cohort) {
if ('operator' in filter) {
delete filter.operator
}
}

return filter
}

Expand Down

0 comments on commit 242e8e9

Please sign in to comment.