{"record":{"id":"c0e6e02209843f9c","repo":"calcom/cal.diy","slug":"event-type-with-id-eventtypeid-not-found-c0e6e0","errorCode":null,"errorMessage":"Event type with id ${eventTypeId} not found","messagePattern":"Event type with id (.+?) not found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"apps/api/v2/src/platform/event-types/event-types_2024_06_14/services/event-types.service.ts","lineNumber":319,"sourceCode":"  ) {\n    if (body.bookingFields) {\n      this.checkHasUserAccessibleEmailBookingField(body.bookingFields);\n    }\n    await this.checkCanUpdateEventType(user.id, eventTypeId, body.scheduleId);\n    const eventTypeUser = await this.getUserToUpdateEvent(user);\n\n    await updateEventType({\n      input: { id: eventTypeId, ...body },\n      ctx: {\n        user: eventTypeUser,\n        prisma: this.dbWrite.prisma,\n      },\n    });\n\n    const eventType = await this.eventTypesRepository.getEventTypeById(eventTypeId);\n\n    if (!eventType) {\n      throw new NotFoundException(`Event type with id ${eventTypeId} not found`);\n    }\n\n    return {\n      ownerId: user.id,\n      ...eventType,\n    };\n  }\n\n  async checkCanUpdateEventType(userId: number, eventTypeId: number, scheduleId: number | undefined | null) {\n    const existingEventType = await this.getUserEventType(userId, eventTypeId);\n    if (!existingEventType) {\n      throw new NotFoundException(`Event type with id ${eventTypeId} not found`);\n    }\n    this.checkUserOwnsEventType(userId, { id: eventTypeId, userId: existingEventType.ownerId });\n    await this.checkUserOwnsSchedule(userId, scheduleId);\n  }\n\n  async getUserToUpdateEvent(user: UserWithProfile) {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/event-types/event-types_2024_06_14/services/event-types.service.ts#L301-L337","documentation":"After updateEventType writes through dbWrite.prisma, the service re-fetches the row via eventTypesRepository.getEventTypeById, which reads from dbRead (the read replica). If that read returns null it throws NotFoundException. The most common root cause is read-replica lag right after the write, but concurrent deletion or a wrong id also produce it.","triggerScenarios":"PATCH/PUT an event type where the write commits but the read replica has not yet propagated it; another process deletes the event type between the update and the re-fetch; the id supplied does not exist (update is a no-op) and the post-update fetch finds nothing.","commonSituations":"Production with primary/replica split and replication lag; high write throughput; a race where a second client deletes the event type mid-update; integration tests that point dbRead and dbWrite at different stores.","solutions":["Retry the GET once after a short backoff to let the replica catch up.","For the post-write read, read from the primary (dbWrite) instead of the read replica to get read-your-writes consistency.","Guard against concurrent deletion by checking existence immediately before and after the update.","Confirm the eventTypeId is owned by the caller before updating so the update is not a silent no-op."],"exampleFix":"// before\nawait updateEventType({ input, ctx });\nconst et = await eventTypesRepository.getEventTypeById(id); // dbRead replica\n// after\nawait updateEventType({ input, ctx });\nconst et = await dbWrite.prisma.eventType.findUnique({ where: { id } });\n// or retry the replica fetch with backoff","handlingStrategy":"retry","validationCode":"async function readAfterWrite(id, fetcher) {\n  for (const delay of [0, 100, 300]) {\n    const et = await fetcher(id);\n    if (et) return et;\n    await new Promise(r => setTimeout(r, delay));\n  }\n  return null;\n}","typeGuard":"null","tryCatchPattern":"try {\n  return await eventTypesRepository.getEventTypeById(id);\n} catch (e) {\n  if (e.name === 'NotFoundException') {\n    // read replica may lag; retry from primary once\n    return await dbWrite.prisma.eventType.findUnique({ where: { id } });\n  }\n  throw e;\n}","preventionTips":["Read from the primary immediately after a write.","Use a single read source in tests to avoid replica lag.","Guard update endpoints against concurrent delete."],"tags":["not-found","replication-lag","race-condition","eventual-consistency","read-after-write"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}