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

SQLite analog of errors 264/269. Thrown in SQLiteRecordManager.update when groupIds length differs from keyStrings length. SQLite uses the same per-key zip pattern, so a mismatch is rejected to prevent row misalignment.

Source

Thrown at packages/components/nodes/recordmanager/SQLiteRecordManager/SQLiteRecordManager.ts:262

        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] ?? null, docIds[i] ?? null])

        const query = `
        INSERT INTO "${tableName}" (key, namespace, updated_at, group_id, doc_id)
        VALUES (?, ?, ?, ?, ?)
        ON CONFLICT (key, namespace) DO UPDATE SET updated_at = excluded.updated_at, doc_id = excluded.doc_id`

        try {
            // To handle multiple files upsert
            for (const record of recordsToUpsert) {
                // Consider using a transaction for batch operations
                await queryRunner.manager.query(query, record.flat())
            }
            await queryRunner.release()
        } catch (error) {
            console.error('Error updating in SQLiteRecordManager:')

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Omit groupIds to default each to null.
  2. Zip and filter keys+groupIds together at the source.
  3. Validate lengths match before the call.

Example fix

// before
await mgr.update(keys, { groupIds: groups })
// after
await mgr.update(keys, { groupIds: keys.map((_, i) => groups[i] ?? null) })
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
  }
  throw e
}

Prevention

When it happens

Trigger: updateOptions.groupIds array with a different count than keys; partial filtering of keys downstream of groupIds; mixing key formats.

Common situations: Ingestion batch slicing keys but not groupIds; deduplication applied to one array only.

Related errors


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