FlowiseAI/Flowise · error · Error

Number of keys (${keyStrings.length}) does not match number

Error message

Number of keys (${keyStrings.length}) does not match number of group_ids ${groupIds.length})

What it means

Postgres analog of error 264. Thrown in PostgresRecordManager.update when the resolved groupIds array length differs from keyStrings length. The Postgres upsert builds one placeholder row per key and zips groupIds positionally, so a length mismatch would misalign rows.

Source

Thrown at packages/components/nodes/recordmanager/PostgresRecordManager/PostgresRecordManager.ts:324

        const queryRunner = dataSource.createQueryRunner()
        const tableName = this.sanitizeTableName(this.tableName)

        const updatedAt = await this.getTime()
        const { timeAtLeast, groupIds: _groupIds } = updateOptions ?? {}

        if (timeAtLeast && updatedAt < timeAtLeast) {
            throw new Error(`Time sync issue with database ${updatedAt} < ${timeAtLeast}`)
        }

        // Handle both new format (objects with uid and docId) and old format (strings)
        const isNewFormat = keys.length > 0 && typeof keys[0] === 'object' && 'uid' in keys[0]
        const keyStrings = isNewFormat ? (keys as Array<{ uid: string; docId: string }>).map((k) => k.uid) : (keys as string[])
        const docIds = isNewFormat ? (keys as Array<{ uid: string; docId: string }>).map((k) => k.docId) : keys.map(() => null)

        const groupIds = _groupIds ?? keyStrings.map(() => null)

        if (groupIds.length !== keyStrings.length) {
            throw new Error(`Number of keys (${keyStrings.length}) does not match number of group_ids ${groupIds.length})`)
        }

        const recordsToUpsert = keyStrings.map((key, i) => [key, this.namespace, updatedAt, groupIds[i], docIds[i]])

        const valuesPlaceholders = recordsToUpsert.map((_, j) => this.generatePlaceholderForRowAt(j, recordsToUpsert[0].length)).join(', ')

        const query = `INSERT INTO "${tableName}" (key, namespace, updated_at, group_id, doc_id) VALUES ${valuesPlaceholders} ON CONFLICT (key, namespace) DO UPDATE SET updated_at = EXCLUDED.updated_at, doc_id = EXCLUDED.doc_id;`
        try {
            await queryRunner.manager.query(query, recordsToUpsert.flat())
            await queryRunner.release()
        } catch (error) {
            console.error('Error updating in PostgresRecordManager:')
            throw error
        } finally {
            await dataSource.destroy()
        }
    }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Omit groupIds if you do not need per-key group assignment - it defaults to all-null.
  2. Keep keys and groupIds zipped at the source and filter them as pairs.
  3. Assert equality before calling update in pipeline code.

Example fix

// before
await mgr.update(keys, { groupIds: groups })  // groups.length !== keys.length
// after
const paired = keys.map((k, i) => [k, groups[i] ?? null])
await mgr.update(paired.map(p => p[0]), { groupIds: paired.map(p => p[1]) })
Defensive patterns

Strategy: validation

Validate before calling

function validateKeysAndGroupIds(keys: unknown[], groupIds?: unknown[]): void {
  if (groupIds && groupIds.length !== keys.length) {
    throw new Error(`groupIds (${groupIds.length}) must equal keys (${keys.length})`)
  }
}

Type guard

function areAligned(keys: unknown[], groupIds: unknown[] | undefined): boolean {
  return !groupIds || groupIds.length === keys.length
}

Try / catch

try {
  await manager.update(keys, { groupIds })
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Number of keys')) {
    // drop groupIds or realign upstream, then retry
  }
  throw e
}

Prevention

When it happens

Trigger: updateOptions.groupIds supplied with a different length than keys; keys filtered downstream while groupIds was not; mixing uid-object keys with a string-array groupIds sized for the old format.

Common situations: Batched ingestion slicing keys but not groupIds; merging de-duplicated keys against un-deduplicated group ids; off-by-one zip bug.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/d5f2d87b68082ab6. Report an issue: GitHub.