Skip to content

fix: resolve 22P02 in api - #2855

Draft
oneuptime-test[bot] wants to merge 1 commit into
masterfrom
oneuptime-fix-exception-40bbd95b
Draft

fix: resolve 22P02 in api#2855
oneuptime-test[bot] wants to merge 1 commit into
masterfrom
oneuptime-fix-exception-40bbd95b

Conversation

@oneuptime-test

Copy link
Copy Markdown

Exception Fix

This pull request was automatically generated by OneUptime AI Agent to fix an exception.

Exception Details

Service: api
Type: 22P02
Message (dynamic values and secrets redacted): invalid input syntax for type uuid: "<HEX_ID>-6fd"

Stack Trace

QueryFailedError: invalid input syntax for type uuid: "<HEX_ID>-6fd"
    at PostgresQueryRunner.query (/usr/src/Common/node_modules/typeorm/src/driver/postgres/PostgresQueryRunner.ts:325:19)
    at processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async SelectQueryBuilder.loadRawResults (/usr/src/Common/node_modules/src/query-builder/SelectQueryBuilder.ts:3818:25)
    at async SelectQueryBuilder.getRawMany (/usr/src/Common/node_modules/src/query-builder/SelectQueryBuilder.ts:1573:29)
    at async SelectQueryBuilder.executeEntitiesAndRawResults (/usr/src/Common/node_modules/src/query-builder/SelectQueryBuilder.ts:3480:26)
    at async SelectQueryBuilder.getRawAndEntities (/usr/src/Common/node_modules/src/query-builder/SelectQueryBuilder.ts:1617:29)
    at async SelectQueryBuilder.getMany (/usr/src/Common/node_modules/src/query-builder/SelectQueryBuilder.ts:1707:25)
    at async Service._findBy (/usr/src/Common/Server/Services/DatabaseService.ts:1617:40)
    at async Service.findOneBy (/usr/src/Common/Server/Services/DatabaseService.ts:1721:42)
    at async Service.onBeforeCreate (/usr/src/Common/Server/Services/IncidentService.ts:637:9)
    at async Service._onBeforeCreate (/usr/src/Common/Server/Services/DatabaseService.ts:291:12)
    at async Service.create (/usr/src/Common/Server/Services/DatabaseService.ts:788:9)
    at async MonitorIncident.criteriaMetCreateIncidentsAndUpdateMonitorStatus (/usr/src/Common/Server/Utils/Monitor/MonitorIncident.ts:662:43)
    at async MonitorResourceUtil.monitorResource (/usr/src/Common/Server/Utils/Monitor/MonitorResource.ts:859:9)
    at async processProbeFromQueue (/usr/src/app/FeatureSet/Telemetry/Jobs/ProbeIngest/ProcessProbeIngest.ts:46:5)
    at async /usr/src/app/FeatureSet/Telemetry/Jobs/TelemetryIngest/ProcessTelemetry.ts:236:19
    at async QueueWorker_1.default.getWorker.concurrency (/usr/src/app/FeatureSet/Telemetry/Jobs/TelemetryIngest/ProcessTelemetry.ts:127:7)
    at async fn (/usr/src/Commo
...(truncated)

Summary of Changes

Summary of Changes

File Modified: Common/Server/Services/IncidentService.ts

Root Cause:
The error invalid input syntax for type uuid: "<HEX_ID>-6fd" occurred because createBy.data.createdIncidentTemplateId is a string field (stored as LongText in the database) that can contain non-UUID values. When this value was used in a database query against the _id column of IncidentTemplate (which is a PostgreSQL UUID type), it was rejected with a syntax error.

The value originates from MonitorIncident.ts where criteriaIncident.id.toString() is assigned to incident.createdIncidentTemplateId. Since CriteriaIncident.id is typed as a plain string, it can contain malformed or truncated values that are not valid UUIDs.

Fix Applied:
Added a UUID format validation check before querying the database. Changed the condition at line 625 from:

} else if (createBy.data.createdIncidentTemplateId) {

to:

} else if (
  createBy.data.createdIncidentTemplateId &&
  ObjectID.isValidUUID(createBy.data.createdIncidentTemplateId.toString())
) {

Why this is the correct fix:

  • Uses the existing ObjectID.isValidUUID() static method (already imported)
  • If the ID is not a valid UUID, the template lookup is gracefully skipped (treated as if no template was provided)
  • Valid UUIDs continue to work exactly as before
  • No changes to validation, authentication, or authorization logic
  • Minimal and targeted — only one additional condition in the specific code path causing the error

Opened as a draft — review before merging. The fix is AI-authored: verify it actually addresses the exception, then mark the pull request ready for review. Nothing is merged automatically.

This PR was automatically generated by OneUptime AI Agent

This commit fixes an exception detected by OneUptime.

Exception Type: 22P02
Exception ID: a3e025c7-35ec-4ed4-8f84-3e0fb8ae8368

Automatically generated by OneUptime AI Agent.
@simlarsen

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant