[miniflare] fix: preserve metadata for present-but-falsy KV values in bulk getWithMetadata#14597
[miniflare] fix: preserve metadata for present-but-falsy KV values in bulk getWithMetadata#14597matingathani wants to merge 2 commits into
Conversation
… bulk getWithMetadata
processKeyValue() gated on the decoded value's truthiness (val && withMetadata)
instead of the key's presence (obj !== null), so bulk getWithMetadata returned
present keys with falsy values (0, false, "") as bare values instead of
{ value, metadata }, losing the metadata.
Fixes cloudflare#14594
🦋 Changeset detectedLatest commit: a68f43a The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Miniflare’s KV bulk getWithMetadata response shaping so that metadata is preserved for keys that exist but decode to falsy values (e.g. 0, false, ""). It aligns bulk-get behavior with the expected Workers KV binding contract: present keys always return { value, metadata }, and only missing keys return bare null.
Changes:
- Fix
processKeyValue()to gate the{ value, metadata }wrapper on key presence (obj !== null) rather than decoded value truthiness. - Add a regression test covering bulk
getWithMetadatafor present-but-falsy decoded JSON/text values. - Add a Miniflare patch changeset describing the bug fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/miniflare/src/workers/kv/namespace.worker.ts |
Fix bulk getWithMetadata response wrapping condition to preserve metadata for present-but-falsy values. |
packages/miniflare/test/plugins/kv/index.spec.ts |
Add regression coverage for falsy decoded values in bulk getWithMetadata. |
.changeset/fix-kv-bulk-metadata-falsy-values.md |
Record the patch-level release note for the Miniflare fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@cloudflare/autoconfig
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fixes #14594
processKeyValue()inpackages/miniflare/src/workers/kv/namespace.worker.tsgated the bulkgetWithMetadataresponse shape on the decoded value's truthiness (val && withMetadata) instead of the key's presence (obj !== null). As a result, present keys whose value happened to be JSON0, JSONfalse, or an empty string were returned as bare unwrapped values instead of{ value, metadata }, silently dropping their metadata.Fix: check entry presence (
obj !== null) instead of value truthiness — the same distinction already used a few lines below for the single-keyGET404 check. Missing-key behavior (barenull) is unchanged.