Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-server): add time component to person.force_upgrade #21899

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ export class PersonState {
// Ensure person properties don't propagate elsewhere, such as onto the event itself.
person.properties = {}

// See documentation on the field.
person.force_upgrade = true
if (this.timestamp > person.created_at.plus({ minutes: 1 })) {
// See documentation on the field.
//
// Note that we account for timestamp vs person creation time (with a little
// padding for good measure) to account for ingestion lag. It's possible for
// events to be processed after person creation even if they were sent prior
// to person creation, and the user did nothing wrong in that case.
person.force_upgrade = true
}

return person
}
Expand Down
9 changes: 6 additions & 3 deletions plugin-server/tests/worker/ingestion/person-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ describe('PersonState.update()', () => {
event: Partial<PluginEvent>,
customHub?: Hub,
processPerson = true,
lazyPersonCreation = false
lazyPersonCreation = false,
timestampParam = timestamp
) {
const fullEvent = {
team_id: teamId,
Expand All @@ -123,7 +124,7 @@ describe('PersonState.update()', () => {
fullEvent as any,
teamId,
event.distinct_id!,
timestamp,
timestampParam,
processPerson,
customHub ? customHub.db : hub.db,
lazyPersonCreation,
Expand Down Expand Up @@ -261,6 +262,7 @@ describe('PersonState.update()', () => {
// `force_upgrade=true` and real Person `uuid` and `created_at`
processPerson = false
const event_uuid = new UUIDT().toString()
const timestampParam = timestamp.plus({ minutes: 5 }) // Event needs to happen after Person creation
const fakePerson = await personState(
{
event: '$pageview',
Expand All @@ -270,7 +272,8 @@ describe('PersonState.update()', () => {
},
hubParam,
processPerson,
lazyPersonCreation
lazyPersonCreation,
timestampParam
).update()
await hub.db.kafkaProducer.flush()

Expand Down
Loading