Skip to content

[miniflare] Fix mixed kvNamespaces and d1Databases records#12986

Merged
petebacondarwin merged 1 commit into
mainfrom
pbacondarwin/fix-mixed-kv-d1-bindings
Mar 20, 2026
Merged

[miniflare] Fix mixed kvNamespaces and d1Databases records#12986
petebacondarwin merged 1 commit into
mainfrom
pbacondarwin/fix-mixed-kv-d1-bindings

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Mar 20, 2026

Fixes the same schema validation bug as was fixed for r2BucketskvNamespaces and d1Databases bindings could not mix plain string values and object values in the same record.

Previously, passing a config like:

new Miniflare({
  kvNamespaces: {
    LOCAL_NS: "local-ns",
    REMOTE_NS: { id: "remote-ns", remoteProxyConnectionString: ... },
  },
})

would throw a Zod validation error because the schema used two separate z.record(...) union branches — one accepting only strings, one accepting only objects. Zod would fail both branches when the values were mixed.

The fix collapses the two z.record(...) branches into a single z.record(z.union([z.string(), z.object({...})])), matching the pattern already applied to r2Buckets. The namespaceEntries() helper in plugins/shared already handled mixed values correctly at runtime — only the schema validation was too restrictive.


  • 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: this is a bug fix for an internal schema validation constraint; no public API surface changed

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@petebacondarwin petebacondarwin marked this pull request as ready for review March 20, 2026 15:01
@petebacondarwin petebacondarwin requested a review from a team as a code owner March 20, 2026 15:01
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 20, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@petebacondarwin petebacondarwin force-pushed the pbacondarwin/fix-mixed-kv-d1-bindings branch from 57a29b2 to 876f943 Compare March 20, 2026 15:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 876f943

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

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 Mar 20, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Mar 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ All changesets look good

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 20, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 876f943

@petebacondarwin petebacondarwin merged commit 5aaaab2 into main Mar 20, 2026
45 checks passed
@petebacondarwin petebacondarwin deleted the pbacondarwin/fix-mixed-kv-d1-bindings branch March 20, 2026 15:51
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants