cloudflare / miniflare

🔥 Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare.
https://miniflare.dev
MIT License
3.78k stars 205 forks source link

KV `list` with prefix over 50 chars causes SQL `LIKE or GLOB pattern too complex` error #690

Closed huw closed 1 year ago

huw commented 1 year ago

Here is a .list() with a prefix less than 50 characters, which works correctly:

await environment.KV.list({
  prefix: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});

Adding one more x:

await environment.KV.list({
  prefix: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});

Causes:

[mf:err] Error: LIKE or GLOB pattern too complex
    at [object Object]
    at Object.list (/code/node_modules/.pnpm/miniflare@3.20230918.0/node_modules/miniflare/src/workers/shared/sql.worker.ts:81:14)
    at KeyValueStorage.list (/code/node_modules/.pnpm/miniflare@3.20230918.0/node_modules/miniflare/src/workers/shared/keyvalue.worker.ts:253:36)
    at KVNamespaceObject.list (/code/node_modules/.pnpm/miniflare@3.20230918.0/node_modules/miniflare/src/workers/kv/namespace.worker.ts:202:36)
    at KVNamespaceObject.fetch (/code/node_modules/.pnpm/miniflare@3.20230918.0/node_modules/miniflare/src/workers/shared/router.worker.ts:42:54)
    at KVNamespaceObject.fetch (/code/node_modules/.pnpm/miniflare@3.20230918.0/node_modules/miniflare/src/workers/shared/object.worker.ts:132:26)

This is very likely to have been caused by afe3da0, which changed this line to db.stmt.

(When I attach a debugger in VS Code—thank you!—it unwraps the following workerd error: workerd/jsg/util.c++:275: error: e = workerd/util/sqlite.c++:830: failed: expected _ec != SQLITE_MISUSE [21 != 21]; SQLite misused: sqlite3_bind_text(statement, i+1, text.begin(), text.size(), SQLITE_STATIC), which is why I’m assuming it’s related to the change from db.prepare)