Skip to content

Bug: getWorkspacesInfo generates invalid SQL IN () when called with empty array (PostgreSQL) #10553

@spatialy

Description

@spatialy

Bug Description

The getWorkspacesInfo account method generates invalid SQL when called with an empty workspace ID array. PostgreSQL rejects WHERE "uuid" IN () as a syntax error. This causes the GitHub integration (and potentially Gmail/Backup) to fail silently every ~6 minutes, and blocks connecting new GitHub repos.

Environment

  • Version: v0.7.375
  • Database: PostgreSQL 17 (self-hosted)
  • Affected service: hardcoreeng/account, called by hardcoreeng/github

Error

PostgresError: syntax error at or near ")"
  position: "74"
  code: "42601"
  method: "getWorkspacesInfo"
  source: "github"

This repeats every ~6 minutes indefinitely. Connecting new GitHub repos fails with platform:status:BadRequest in the transactor.

Root Cause

server/account/src/collections/postgres/postgres.ts ~line 177buildWhereClause does not handle empty $in arrays:

case '$in': {
  const inVals = Object.values(qKey as object)[0]
  const inVars: string[] = []
  for (const val of inVals) {      // empty array → no iterations
    currIdx++
    inVars.push(formatVar(currIdx, castType))
    values.push(val)
  }
  whereChunks.push(`"${snakeKey}" IN (${inVars.join(', ')})`)  // → IN ()
  break
}

When inVals is [], this produces IN () which is invalid SQL in PostgreSQL (and CockroachDB).

server/account/src/operations.ts ~line 1617getWorkspacesInfo checks ids == null but not ids.length === 0, so empty arrays pass through to the query.

services/github/pod-github/src/platform.ts ~line 1040 — the GitHub service calls getWorkspacesInfo(workspaces) without guarding for empty arrays. When there are no integrations, workspaces is [].

Impact

Caller Guards empty array?
pod-github/src/platform.ts ~1040 No
pod-gmail/src/gmailController.ts ~196 No
server/backup/src/service.ts ~283 No
pod-calendar/src/calendarController.ts ~75 Yesif (ids.length === 0) return

The calendar service is the only caller that properly guards against this.

Suggested Fix

Either (or both):

Option A — Fix at the query level in getWorkspacesInfoWithStatusByIds (server/account/src/utils.ts ~line 1350):

if (uuids.length === 0) return []

Option B — Fix at the SQL builder level in buildWhereClause (postgres.ts):

case '$in': {
  const inVals = Object.values(qKey as object)[0]
  if (inVals.length === 0) {
    whereChunks.push('FALSE')
    break
  }
  // ... existing code
}

Option B is more defensive and prevents the same bug from other callers.

Reproduction

  1. Self-host Huly v0.7.375 on PostgreSQL (not CockroachDB)
  2. Configure the GitHub integration (GITHUB_APPID, etc.)
  3. Install the GitHub App on an organization
  4. Observe account service logs — getWorkspacesInfo errors every ~6 minutes
  5. Try to connect a repo to a project — fails with BadRequest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions