cloudflare / cloudflare/workers-sdk

wrangler command that offer to add to wrangler.jsonc don't respect existing binding to same resource - should they?

Open
#10,726 2 comments 0 reactions 1 assignee Claimed by @penalosa View on GitHub
package:wrangler product:d1
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### What versions & operating system are you using?

Wrangler 4.38.0, macos latest

### Please provide a link to a minimal reproduction

https://github.com/irvinebroque/workers-for-platforms-example/pull/1/files

### Describe the Bug

https://github.com/irvinebroque/workers-for-platforms-example/pull/1/files

Run:

```
npx wrangler d1 create workers-for-platforms-example-project
```

This will offer to add to your wrangler.jsonc file. But a binding to that DB already exists (by name but not by ID)

```diff
"d1_databases": [
{
"binding": "workers_for_platforms_example_project",
"database_name": "workers-for-platforms-example-project",
"database_id": ""
+ },
+ {
+ "binding": "workers_for_platforms_example_project",
+ "database_name": "workers-for-platforms-example-project",
+ "database_id": "c24ad881-6061-4a1b-b83f-d2199ea92a02"
+ }
],
```

This is a common pattern because people add the binding name, the binding identifier, and then leave the ID blank — expecting the user to fill this in.

Now, Wrangler can do this, but you then kind of end up with two bindings, both with the same name. And you end up here:

```
✘ [ERROR] Processing wrangler.jsonc configuration:

- workers_for_platforms_example_project assigned to multiple D1 Database bindings.
- Bindings must have unique names, so that they can all be referenced in the worker.
Please change your bindings to have unique names.
```

refs https://github.com/cloudflare/workers-for-platforms-example/pull/42

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.