Skip to content

[SQLite]: fix libsql cache JSON roundtrip regression#5563

Open
muhammadosama984 wants to merge 1 commit intodrizzle-team:mainfrom
muhammadosama984:fix/libsql-cache-json-roundtrip-5561
Open

[SQLite]: fix libsql cache JSON roundtrip regression#5563
muhammadosama984 wants to merge 1 commit intodrizzle-team:mainfrom
muhammadosama984:fix/libsql-cache-json-roundtrip-5561

Conversation

@muhammadosama984
Copy link
Copy Markdown

@muhammadosama984 muhammadosama984 commented Mar 30, 2026

Fixes #5561

Summary

  • Convert libSQL values() rows to plain arrays before storing them in cache so JSON roundtrips preserve positional data used by result mapping
  • Add a drizzle-orm unit regression test that mocks libSQL row shape and reproduces the cache-hit JSON-roundtrip scenario
  • Add a libsql integration regression test that validates cached query results with JSON columns on subsequent reads

Root Cause

LibSQL Row objects are plain objects with both named keys and non-enumerable numeric indices + length. JSON.stringify only serializes enumerable own properties, so numeric indices are lost during the cache roundtrip. On cache hit, Array.prototype.slice.call(row) returns an empty array, causing mapResultRow to read undefined and crash with SyntaxError: "undefined" is not valid JSON.

Fix

In drizzle-orm/src/libsql/session.ts, the values() method now converts each Row to a plain Array via Array.prototype.slice.call(row) before passing it to queryWithCache. This ensures the data survives any JSON-based serialization (Upstash Redis, custom caches, etc.).

Test plan

  • pnpm test in drizzle-orm — all unit tests pass, including new regression test
  • pnpm test:types in drizzle-orm — type checks pass
  • LIBSQL_URL='file:./tmp-libsql.db' pnpm exec vitest run tests/sqlite/libsql.test.ts in integration-tests — integration regression test passes

Convert libSQL values rows to plain arrays before caching so JSON-based caches keep positional data and avoid decode failures on cache hits. Add regression coverage in both drizzle-orm unit tests and libsql integration tests.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Upstash cache broken with libSQL driver — Row objects lose numeric indices after JSON roundtrip

1 participant