You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
D1 bind(): typed arrays and DataView store text or an empty blob instead of their bytes #7785
D1Database.prepare(...).bind(...) converts typed arrays and DataView with Array.from(view) in src/cloudflare/internal/d1-api.ts:660. Array.from enumerates the view element-wise, so the raw bytes never reach the storage layer, and the Uint8Array fast path is bypassed.
A Uint16Array([300]) is stored as the text "300", and a DataView becomes an empty blob. Binding the same bytes through a raw Durable Object SqlStorage stores them correctly, which isolates the problem to this one conversion.
What I expected
A typed array or DataView bind parameter stores its raw bytes — the documented way to bind binary data.
What I saw (production D1 and the local simulator)
bound value
production stores
local simulator stores
new Uint16Array([300])
TEXT "300"
truncated blob 0x2C
new Float64Array([300, 1.5])
TEXT "300,1.5"
truncated blob
new DataView(new ArrayBuffer(4))
empty blob
empty blob
[1.5] (plain number array)
byte 01 (truncated)
byte 01
So the same code behaves differently in wrangler dev and in production, and binary data is not byte-recoverable.
How to reproduce
Create a table with a BLOB column.
Bind each value above on both paths, then read the value back (typeof, length, hex).
Control: ctx.storage.sql.exec("insert ...", new Uint8Array([1,2])) from a Durable Object stores byte-wise correctly.
Reproduction scripts and the full local/remote matrices are available if useful.
Suggested fix
Replace Array.from(view) with view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength), or new Uint8Array(view.buffer, view.byteOffset, view.byteLength).
Environment
wrangler 4.151.1, production D1 on my own account, and the local simulator.
Activity