Skip to content

[miniflare] fix: preserve metadata for present-but-falsy KV values in bulk getWithMetadata#14597

Open
matingathani wants to merge 2 commits into
cloudflare:mainfrom
matingathani:fix/kv-bulk-metadata-falsy-values
Open

[miniflare] fix: preserve metadata for present-but-falsy KV values in bulk getWithMetadata#14597
matingathani wants to merge 2 commits into
cloudflare:mainfrom
matingathani:fix/kv-bulk-metadata-falsy-values

Conversation

@matingathani

@matingathani matingathani commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #14594

processKeyValue() in packages/miniflare/src/workers/kv/namespace.worker.ts gated the bulk getWithMetadata response 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 JSON 0, JSON false, 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-key GET 404 check. Missing-key behavior (bare null) is unchanged.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal bug fix restoring documented/tested contract, no user-facing API change

Open in Devin Review

… 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
Copilot AI review requested due to automatic review settings July 8, 2026 06:19
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a68f43a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
miniflare Patch
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 8, 2026
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team July 8, 2026 06:19
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/workers-kv
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-kv-bulk-metadata-falsy-values.md: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/kv/namespace.worker.ts: [@cloudflare/workers-kv @cloudflare/wrangler]
  • packages/miniflare/test/plugins/kv/index.spec.ts: [@cloudflare/workers-kv @cloudflare/wrangler]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getWithMetadata for 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.

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14597

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14597

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14597

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14597

miniflare

npm i https://pkg.pr.new/miniflare@14597

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14597

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14597

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14597

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14597

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14597

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14597

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14597

wrangler

npm i https://pkg.pr.new/wrangler@14597

commit: a68f43a

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

miniflare KV bulk getWithMetadata drops metadata for present-but-falsy values (0, false, empty string)

3 participants