From ecd47719e3b95547f268aef94aa104e32c0bfa1c Mon Sep 17 00:00:00 2001 From: Tiina Turban Date: Wed, 27 Sep 2023 18:08:24 +0200 Subject: [PATCH] chore: Ignore {} unset value instead of DLQ the event (#17633) --- .../src/worker/ingestion/person-state.ts | 5 +++- .../tests/main/process-event.test.ts | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugin-server/src/worker/ingestion/person-state.ts b/plugin-server/src/worker/ingestion/person-state.ts index 72a82a07d0aec..16cae0d5e1a1e 100644 --- a/plugin-server/src/worker/ingestion/person-state.ts +++ b/plugin-server/src/worker/ingestion/person-state.ts @@ -226,7 +226,10 @@ export class PersonState { const properties: Properties = this.eventProperties['$set'] || {} const propertiesOnce: Properties = this.eventProperties['$set_once'] || {} - const unsetProperties: Array = this.eventProperties['$unset'] || [] + const unsetProps = this.eventProperties['$unset'] + const unsetProperties: Array = Array.isArray(unsetProps) + ? unsetProps + : Object.keys(unsetProps || {}) || [] // Figure out which properties we are actually setting Object.entries(propertiesOnce).map(([key, value]) => { diff --git a/plugin-server/tests/main/process-event.test.ts b/plugin-server/tests/main/process-event.test.ts index 94505831b8452..23b90c84fc5c9 100644 --- a/plugin-server/tests/main/process-event.test.ts +++ b/plugin-server/tests/main/process-event.test.ts @@ -2791,6 +2791,35 @@ test('$unset person property', async () => { expect(person.properties).toEqual({ b: 2 }) }) +test('$unset person empty set ignored', async () => { + await createPerson(hub, team, ['distinct_id1'], { a: 1, b: 2, c: 3 }) + + await processEvent( + 'distinct_id1', + '', + '', + { + event: 'some_event', + properties: { + token: team.api_token, + distinct_id: 'distinct_id1', + $unset: {}, + }, + } as any as PluginEvent, + team.id, + now, + new UUIDT().toString() + ) + expect((await hub.db.fetchEvents()).length).toBe(1) + + const [event] = await hub.db.fetchEvents() + expect(event.properties['$unset']).toEqual({}) + + const [person] = await hub.db.fetchPersons() + expect(await hub.db.fetchDistinctIdValues(person)).toEqual(['distinct_id1']) + expect(person.properties).toEqual({ a: 1, b: 2, c: 3 }) +}) + describe('ingestion in any order', () => { const ts0: DateTime = now const ts1: DateTime = now.plus({ minutes: 1 })