Skip to content

Commit 4030ace

Browse files
authored
fix: prevent bot attr corruption during ingestion on member updates (#3419)
1 parent 260b6e5 commit 4030ace

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

services/apps/data_sink_worker/src/service/member.service.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
IMemberData,
3333
IMemberIdentity,
3434
IOrganizationIdSource,
35+
MemberAttributeName,
3536
MemberBotDetection,
3637
MemberIdentityType,
3738
OrganizationAttributeSource,
@@ -301,7 +302,7 @@ export default class MemberService extends LoggerBase {
301302
data.displayName = getProperDisplayName(data.displayName)
302303
}
303304

304-
const toUpdate = MemberService.mergeData(original, originalIdentities, data)
305+
const toUpdate = this.mergeData(original, originalIdentities, data)
305306

306307
if (toUpdate.attributes) {
307308
this.log.trace({ memberId: id }, 'Setting attribute default values!')
@@ -627,7 +628,7 @@ export default class MemberService extends LoggerBase {
627628
return toReturn
628629
}
629630

630-
private static mergeData(
631+
private mergeData(
631632
dbMember: IDbMember,
632633
dbIdentities: IMemberIdentity[],
633634
member: IMemberUpdateData,
@@ -674,6 +675,21 @@ export default class MemberService extends LoggerBase {
674675

675676
let attributes: Record<string, unknown> | undefined
676677
if (member.attributes) {
678+
const incomingIsBot = member.attributes?.[MemberAttributeName.IS_BOT]?.[PlatformType.GITHUB]
679+
const existingIsBot = dbMember.attributes?.[MemberAttributeName.IS_BOT]?.[PlatformType.GITHUB]
680+
681+
// Incoming data flags the member as a bot, but the existing record does not
682+
// This is likely corrupted; discard the incoming attributes
683+
// If the member were actually a bot, the flag would have been set at creation.
684+
if (incomingIsBot && !existingIsBot) {
685+
this.log.warn(
686+
{ memberId: dbMember.id },
687+
'Member attributes appear corrupted due to bot attributes',
688+
)
689+
690+
member.attributes = {} // Preserve existing member attributes
691+
}
692+
677693
const temp = mergeWith({}, dbMember.attributes, member.attributes)
678694
const manuallyChangedFields: string[] = dbMember.manuallyChangedFields || []
679695

0 commit comments

Comments
 (0)