Skip to content

Commit

Permalink
chore: Ignore {} unset value instead of DLQ the event (#17633)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiina303 authored Sep 27, 2023
1 parent e7d5d3b commit ecd4771
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ export class PersonState {

const properties: Properties = this.eventProperties['$set'] || {}
const propertiesOnce: Properties = this.eventProperties['$set_once'] || {}
const unsetProperties: Array<string> = this.eventProperties['$unset'] || []
const unsetProps = this.eventProperties['$unset']
const unsetProperties: Array<string> = Array.isArray(unsetProps)
? unsetProps
: Object.keys(unsetProps || {}) || []

// Figure out which properties we are actually setting
Object.entries(propertiesOnce).map(([key, value]) => {
Expand Down
29 changes: 29 additions & 0 deletions plugin-server/tests/main/process-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit ecd4771

Please sign in to comment.