Skip to content

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

Closed

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 177 — buildWhereClause 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 1617 — getWorkspacesInfo 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 Yes — if (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

Activity

  1. huly-github-staging commented on Feb 25, 2026

    @huly-github-staging

    Connected to Huly®: UBERF-15672

  2. changed the title [-]getWorkspacesInfo generates invalid SQL IN () when called with empty array (PostgreSQL)[/-] [+]Bug: getWorkspacesInfo generates invalid SQL IN () when called with empty array (PostgreSQL)[/+] on Feb 25, 2026
  3. added a commit that references this issue on Feb 25, 2026
    fe7e1ad
  4. added a commit that references this issue on Feb 25, 2026
    66deebd
  5. added a commit that references this issue on Jul 9, 2026
    9282c42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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