:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(taxonomic-filter): preserve identifier fields on pinned items (#59766)
Paul D'Ambra17d868e55b1b
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsxindex f76e9fbbf2fe..df0aabeddce5 100644--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx@@ -129,4 +129,56 @@ describe('TaxonomicFilter pinning', () => {expect(pinButtons.length).toBeGreaterThan(0)})})++ it.each([+ {+ description: 'fresh person pin with full distinct_ids',+ value: 'distinct-abc',+ storedItem: { name: 'Alice', distinct_ids: ['distinct-abc'] },+ },+ {+ description: 'pre-existing pin shrunk to just { name } (old localStorage shape)',+ value: 'distinct-abc',+ storedItem: { name: 'distinct-abc' },+ },+ ])('does not crash when hovering a pinned Person item: $description', async ({ value, storedItem }) => {+ const logic = taxonomicFilterPinnedPropertiesLogic.build()+ logic.mount()+ // Seed the persisted shape directly so we can exercise both the new (full)+ // and the old ({ name }-only) localStorage entry shapes.+ logic.actions.setPinnedFilters([+ {+ groupType: TaxonomicFilterGroupType.Persons,+ groupName: 'Persons',+ value,+ item: storedItem,+ timestamp: Date.now(),+ },+ ])++ renderFilter({+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Persons],+ popoverEnabled: true,+ })++ await waitFor(() => {+ expect(screen.getByTestId('taxonomic-tab-pinned_filters')).toBeInTheDocument()+ })++ await userEvent.click(screen.getByTestId('taxonomic-tab-pinned_filters'))++ const pinnedRow = await screen.findByTestId('prop-filter-pinned_filters-0')++ // Hovering the row triggers ControlledDefinitionPopover, which calls the+ // source group's getValue on the stored item. Before the fix, the old+ // `{ name }`-only shape threw `TypeError: Cannot read properties of+ // undefined (reading '0')` here because Persons read `distinct_ids[0]`.+ // Awaiting the async hover ensures any rejection from a synchronous+ // render throw fails the test, and the positive `Person` popover-header+ // assertion proves the chain ran to completion — not just "didn't throw".+ await userEvent.hover(pinnedRow)+ expect(await screen.findByText('Person')).toBeInTheDocument()++ logic.unmount()+ })})diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.tsindex 7caa08a23753..0d524e6ead7c 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts@@ -846,6 +846,47 @@ describe('taxonomicFilterLogic', () => {expect(new Set(values).size).toBe(values.length)})})++ describe('Persons group getValue tolerates pinned items missing distinct_ids', () => {+ let testLogic: ReturnType<typeof taxonomicFilterLogic.build>++ beforeEach(() => {+ testLogic = taxonomicFilterLogic({+ taxonomicFilterLogicKey: 'personsGetValueTest',+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Persons],+ })+ testLogic.mount()+ })++ afterEach(() => {+ testLogic.unmount()+ })++ it.each([+ {+ description: 'fresh person with distinct_ids returns the first id',+ person: { name: 'Alice', distinct_ids: ['distinct-abc', 'distinct-old'] },+ expected: 'distinct-abc',+ },+ {+ description: 'pre-existing pinned entry shrunk to { name } returns undefined without throwing',+ person: { name: 'distinct-abc' },+ expected: undefined,+ },+ {+ description: 'empty distinct_ids array returns undefined without throwing',+ person: { name: 'Alice', distinct_ids: [] },+ expected: undefined,+ },+ ])('$description', ({ person, expected }) => {+ const personsGroup = testLogic.values.taxonomicGroups.find(+ (g) => g.type === TaxonomicFilterGroupType.Persons+ )+ expect(personsGroup?.getValue).toBeDefined() // oxlint-disable-line jest/no-restricted-matchers+ expect(() => personsGroup?.getValue?.(person as any)).not.toThrow()+ expect(personsGroup?.getValue?.(person as any)).toBe(expected)+ })+ })})describe('redistributeTopMatches', () => {diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsxindex 23d4dc598df7..9bd831398cd2 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx@@ -1216,7 +1216,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([type: TaxonomicFilterGroupType.Persons,endpoint: `api/environments/${teamId}/persons/`,getName: (person: PersonType) => person.name || 'Anon user?',- getValue: (person: PersonType) => person.distinct_ids[0],+ getValue: (person: PersonType) => person.distinct_ids?.[0],getPopoverHeader: () => `Person`,},{diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.test.tsindex 43caa825f353..9ee66be0a30e 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.test.ts@@ -2,6 +2,7 @@ import { initKeaTests } from '~/test/init'import {hasPinnedContext,+ pickMinimalPinnedItem,stripPinnedContext,taxonomicFilterPinnedPropertiesLogic,} from './taxonomicFilterPinnedPropertiesLogic'@@ -28,7 +29,7 @@ describe('taxonomicFilterPinnedPropertiesLogic', () => {expect(logic.values.pinnedFilters).toEqual([])})- it('togglePin adds an item storing only { name } regardless of what was passed', () => {+ it('togglePin stores the item with PII / heavy fields stripped', () => {const item = { name: '$browser', id: 'prop-1', description: 'some desc', tags: ['a'] }logic.actions.togglePin(TaxonomicFilterGroupType.EventProperties, 'Event properties', '$browser', item)@@ -39,12 +40,104 @@ describe('taxonomicFilterPinnedPropertiesLogic', () => {groupType: TaxonomicFilterGroupType.EventProperties,groupName: 'Event properties',value: '$browser',- item: { name: '$browser' },+ item: { name: '$browser', id: 'prop-1', description: 'some desc', tags: ['a'] },}))expect(typeof filters[0].timestamp).toBe('number')})+ it.each([+ {+ description: 'Persons preserves distinct_ids so person.distinct_ids[0] does not throw',+ groupType: TaxonomicFilterGroupType.Persons,+ value: 'distinct-abc',+ item: { name: 'Alice', distinct_ids: ['distinct-abc', 'distinct-old'], uuid: 'u-1' },+ expectedItem: { name: 'Alice', distinct_ids: ['distinct-abc', 'distinct-old'], uuid: 'u-1' },+ getValue: (it: any) => it.distinct_ids[0],+ expectedGetValue: 'distinct-abc',+ },+ {+ description: 'Insights preserves short_id',+ groupType: TaxonomicFilterGroupType.Insights,+ value: 'sh0rt',+ item: { name: 'My insight', short_id: 'sh0rt', id: 42 },+ expectedItem: { name: 'My insight', short_id: 'sh0rt', id: 42 },+ getValue: (it: any) => it.short_id,+ expectedGetValue: 'sh0rt',+ },+ {+ description: 'Actions preserves id',+ groupType: TaxonomicFilterGroupType.Actions,+ value: 7,+ item: { name: 'Signup', id: 7, steps: [{ tag_name: 'button' }] },+ expectedItem: { name: 'Signup', id: 7, steps: [{ tag_name: 'button' }] },+ getValue: (it: any) => it.id,+ expectedGetValue: 7,+ },+ {+ description: 'Notebooks preserves short_id and title',+ groupType: TaxonomicFilterGroupType.Notebooks,+ value: 'nb-1',+ item: { title: 'Research', short_id: 'nb-1' },+ expectedItem: { name: 'nb-1', short_id: 'nb-1', title: 'Research' },+ getValue: (it: any) => it.short_id,+ expectedGetValue: 'nb-1',+ },+ {+ description: 'FeatureFlags preserves id, key and active',+ groupType: TaxonomicFilterGroupType.FeatureFlags,+ value: 99,+ item: { id: 99, key: 'new-thing', name: 'New thing', active: false },+ expectedItem: { id: 99, key: 'new-thing', name: 'New thing', active: false },+ getValue: (it: any) => it.id || '',+ expectedGetValue: 99,+ },+ {+ description: 'Groups preserves group_key and the display name',+ groupType: TaxonomicFilterGroupType.GroupsPrefix,+ value: 'org-123',+ item: { group_key: 'org-123', name: 'Acme Inc', group_type_index: 0 },+ expectedItem: { group_key: 'org-123', name: 'Acme Inc', group_type_index: 0 },+ getValue: (it: any) => it.group_key,+ expectedGetValue: 'org-123',+ },+ ])(+ 'togglePin minimal item allows source-group getValue to run: $description',+ ({ groupType, value, item, expectedItem, getValue, expectedGetValue }) => {+ logic.actions.togglePin(groupType, 'irrelevant', value, item)+ const storedItem = logic.values.pinnedFilters[0].item+ expect(storedItem).toEqual(expectedItem)+ expect(() => getValue(storedItem)).not.toThrow()+ expect(getValue(storedItem)).toEqual(expectedGetValue)+ }+ )++ it.each([+ {+ description: 'strips Person email and properties',+ item: { name: 'Alice', distinct_ids: ['d1'], email: '[email protected]', properties: { plan: 'pro' } },+ expectedItem: { name: 'Alice', distinct_ids: ['d1'] },+ },+ {+ description: 'strips group_properties',+ item: { name: 'Acme', group_key: 'org-1', group_properties: { revenue: 12345 } },+ expectedItem: { name: 'Acme', group_key: 'org-1' },+ },+ {+ description: 'strips a stale _pinnedContext if one happens to be on the source item',+ item: { name: 'x', id: 1, _pinnedContext: { sourceGroupType: 'events', sourceGroupName: 'Events' } },+ expectedItem: { name: 'x', id: 1 },+ },+ ])('togglePin strips PII / heavy fields before persisting: $description', ({ item, expectedItem }) => {+ logic.actions.togglePin(TaxonomicFilterGroupType.Persons, 'Persons', 'pv', item)+ expect(logic.values.pinnedFilters[0].item).toEqual(expectedItem)+ })++ it('togglePin falls back to value for name when item lacks a name', () => {+ logic.actions.togglePin(TaxonomicFilterGroupType.EventProperties, 'Event properties', '$os', {})+ expect(logic.values.pinnedFilters[0].item).toEqual({ name: '$os' })+ })+it('togglePin removes an existing item when called again with the same groupType and value', () => {const item = { name: '$browser' }logic.actions.togglePin(TaxonomicFilterGroupType.EventProperties, 'Event properties', '$browser', item)@@ -223,6 +316,55 @@ describe('taxonomicFilterPinnedPropertiesLogic', () => {})})+ describe('pickMinimalPinnedItem', () => {+ it.each([+ {+ description: 'strips denylisted fields and keeps everything else',+ input: { name: 'Alice', distinct_ids: ['d1'], email: '[email protected]', properties: { big: 'blob' } },+ fallback: 'fallback',+ expected: { name: 'Alice', distinct_ids: ['d1'] },+ },+ {+ description: 'uses fallback value when name is missing',+ input: { id: 5 },+ fallback: 'fb',+ expected: { id: 5, name: 'fb' },+ },+ {+ description: 'uses fallback value when name is null (matches the original ?? value semantics)',+ input: { id: 5, name: null },+ fallback: 'fb',+ expected: { id: 5, name: 'fb' },+ },+ {+ description: 'handles non-object input by returning just the fallback name',+ input: null,+ fallback: 'only-name',+ expected: { name: 'only-name' },+ },+ {+ description: 'rejects array input by returning just the fallback name',+ input: ['a', 'b'],+ fallback: 'arr',+ expected: { name: 'arr' },+ },+ {+ description: 'drops undefined-valued fields and functions',+ input: { name: 'x', undef: undefined, fn: () => 1, keep: 'me' },+ fallback: 'x',+ expected: { name: 'x', keep: 'me' },+ },+ {+ description: 'strips a stale _pinnedContext from the source item',+ input: { name: 'x', _pinnedContext: { sourceGroupType: 'events', sourceGroupName: 'Events' } },+ fallback: 'x',+ expected: { name: 'x' },+ },+ ])('$description', ({ input, fallback, expected }) => {+ expect(pickMinimalPinnedItem(input, fallback)).toEqual(expected)+ })+ })+describe('stripPinnedContext', () => {it('removes _pinnedContext and returns remaining fields', () => {const item = {diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.tsindex 8f7e19bbcb68..eeb18a92ff4e 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic.ts@@ -35,6 +35,33 @@ export function stripPinnedContext<T extends Record<string, any>>(item: T): Omitreturn clean}+/**+ * Fields stripped before persisting a pinned item to localStorage. The list covers+ * the obvious PII / heavy-blob fields that source-group items may carry — Person+ * `email` and `properties`, Group `group_properties`, etc. Everything else flows+ * through so source-group `getValue` and `getName` keep working without us having+ * to enumerate every identifier field they read.+ */+const PINNED_ITEM_DENYLIST = new Set<string>(['email', 'properties', 'group_properties', '_pinnedContext'])++export function pickMinimalPinnedItem(item: unknown, fallbackValue: TaxonomicFilterValue): Record<string, any> {+ if (typeof item !== 'object' || item == null || Array.isArray(item)) {+ return { name: fallbackValue }+ }+ const source = item as Record<string, any>+ const picked: Record<string, any> = {}+ for (const [field, fieldValue] of Object.entries(source)) {+ if (PINNED_ITEM_DENYLIST.has(field) || fieldValue === undefined || typeof fieldValue === 'function') {+ continue+ }+ picked[field] = fieldValue+ }+ if (picked.name == null) {+ picked.name = fallbackValue+ }+ return picked+}+const OLD_PERSIST_KEY = 'scenes.session-recordings.player.playerSettingsLogic.quickFilterProperties'const teamId = typeof window !== 'undefined' ? window.POSTHOG_APP_CONTEXT?.current_team?.id : undefined@@ -79,7 +106,7 @@ export const taxonomicFilterPinnedPropertiesLogic = kea<taxonomicFilterPinnedProgroupType,groupName,value,- item: { name: item?.name ?? value },+ item: pickMinimalPinnedItem(item, value),timestamp: Date.now(),}diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsxindex 657edb44bec7..9dfc69dc4ac1 100644--- a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx@@ -789,7 +789,7 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonomitype: TaxonomicFilterGroupType.Persons,endpoint: `api/environments/${teamId}/persons/`,getName: (person: PersonType) => person.name || 'Anon user?',- getValue: (person: PersonType) => person.distinct_ids[0],+ getValue: (person: PersonType) => person.distinct_ids?.[0],getPopoverHeader: () => `Person`,},{