Skip to content

fix: resolve QueryFailedError in api - #3138

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

fix: resolve QueryFailedError in api#3138
oneuptime-test[bot] wants to merge 1 commit into
masterfrom
oneuptime-fix-exception-a25673aa

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: QueryFailedError
Message (dynamic values and secrets redacted): invalid input syntax for type uuid: "<HEX_ID>-63b"

Stack Trace

QueryFailedError: invalid input syntax for type uuid: "<HEX_ID>-63b"
    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:1854:40)
    at async Service.findOneBy (/usr/src/Common/Server/Services/DatabaseService.ts:2019:42)
    at async Service.onBeforeCreate (/usr/src/Common/Server/Services/IncidentService.ts:728:9)
    at async Service._onBeforeCreate (/usr/src/Common/Server/Services/DatabaseService.ts:294:12)
    at async Service.create (/usr/src/Common/Server/Services/DatabaseService.ts:978:9)
    at async MonitorIncident.criteriaMetCreateIncidentsAndUpdateMonitorStatus (/usr/src/Common/Server/Utils/Monitor/MonitorIncident.ts:711:43)
    at async MonitorResourceUtil.monitorResource (/usr/src/Common/Server/Utils/Monitor/MonitorResource.ts:935: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:335:19
    at async QueueWorker_1.default.getWorker.concurrency (/usr/src/app/FeatureSet/Telemetry/Jobs/TelemetryIngest/ProcessTelemetry.ts:226:7)
    at async fn (/usr/src/Commo
...(truncated)

Summary of Changes

Summary

Root Cause: The QueryFailedError: invalid input syntax for type uuid: "<HEX_ID>-63b" occurred because IncidentService.onBeforeCreate() was using createBy.data.createdIncidentTemplateId as a UUID in a database query (IncidentTemplateService.findOneBy), but this field can contain two different types of values:

  1. A valid UUID — when set from the API/UI, referencing an actual IncidentTemplate database record
  2. A criteria template ID string (e.g., <HEX_ID>-63b) — when set automatically by MonitorIncident.ts during probe-driven incident creation. This is just a short identifier for the monitor criteria template, NOT a database UUID.

When the value was a criteria template ID, it was passed directly to PostgreSQL as a UUID parameter, causing the invalid input syntax for type uuid error.

Fix Applied: In Common/Server/Services/IncidentService.ts, line ~716, the condition that gates the IncidentTemplate lookup was changed from:

} else if (createBy.data.createdIncidentTemplateId) {

to:

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

This ensures the template lookup block only executes when createdIncidentTemplateId is both present AND a valid UUID. When the value is a criteria template ID (non-UUID), the block is skipped, and the incident creation proceeds normally using the default "created" incident state fallback.

What was NOT done (budget exhausted): TypeScript compilation verification could not be completed due to npm cache permission issues, but the fix uses the existing ObjectID.isValidUUID() static method which is already imported in the file and follows the same patterns used elsewhere in the codebase.


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

ℹ️ Verification

Not verified — the repository has no setup/build/test commands configured. Configure them on the code repository to have fixes verified before the pull request opens.

This commit fixes an exception detected by OneUptime.

Exception Type: QueryFailedError
Exception ID: b505f507-2772-491c-8f6c-d7d4cef8e999

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