-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG: When the environment variable is empty, bindings from another environment are loaded. [resolved] #6130
Comments
This is because your wrangler.toml is not valid. If you converted it to JSON it would look like this: {
"compatibility_date": "2024-06-20",
"compatibility_flags": [
"nodejs_compat"
],
"main": "src/index.ts",
"name": "empty-variable-in-wrangler",
"d1_databases": [
{
"binding": "DB",
"database_id": "<stg-db-id>",
"database_name": "db-stg"
},
{
"binding": "DB",
"database_id": "<prd-db-id>",
"database_name": "db"
}
],
"env": {
"d1_databases": [
{
"binding": "DB",
"database_id": "<prd-db-id>",
"database_name": "db"
}
],
"stg": {
"d1_databases": [
{
"binding": "DB",
"database_id": "<stg-db-id>",
"database_name": "db-stg"
}
]
}
}
} You can see that you have added two DB bindings to the top-level - amongst other issues. We have a PR to provide better errors in this case: #5737 |
@petebacondarwin So, I can't switch the database binding by the stage name, can I? Thanks. |
I'm not quite sure what you mean but I think what you want in your wrangler.toml is something like: d1_databases = [
{ binding = "DB", database_name = "db", database_id = "<prd-db-id>" },
]
[env.stg]
d1_databases = [
{ binding = "DB", database_name = "db-stg", database_id = "<stg-db-id>" },
] What this does is set the prod-db-id as the top level environment and the std-db-id for the |
@petebacondarwin I did it!! Thanks for your advice! |
Which Cloudflare product(s) does this pertain to?
Wrangler core
What version(s) of the tool(s) are you using?
3.61.0
What version of Node are you using?
v22.1.0
What operating system and version are you using?
Sonoma 14.4.1
Describe the Bug
Observed behavior
I want to use different D1 for the validation environment and the production environment. To do so, I set up wrangler.toml as follows:
Then deploy to Cloudflare Workers it with the
wrangler deploy
command.However, this configuration will cause the deployment to fail with the following error:
Expected behavior
This is probably due to the fact that the value of
env.stg
is being read even though the environment variable has not been set.If I set the environment variable to
stg
, this works fine.However, I don't want the production app name to have
-prd
attached to it, so I want to deploy it with empty environment variables.Thanks for reading.
Please provide a link to a minimal reproduction
https://github.com/ogadra/empty-variable-in-wrangler
Please provide any relevant error logs
No response
The text was updated successfully, but these errors were encountered: