cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.42k stars 593 forks source link

🐛 BUG: Executing SQL queries from Wrangler CLI is failing while it works from the dashboard #5523

Open ElvisAns opened 3 months ago

ElvisAns commented 3 months ago

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

wrangler 3.47.1

What version of Node are you using?

v20.11.1

What operating system and version are you using?

Windows 11

Describe the Bug

Observed behavior

Whenever i try to execute SQL queries to D1 via Wrangler it keeps failing telling me : The request is malformed: failed to decode id [code: 7400]

Here is the wrangler command npx wrangler d1 execute database --remote --command "INSERT INTO notes (text) VALUES ('The best pizza topping is pepperoni')"

Expected behavior

The command should insert the data because the table 'notes' ; i created it manually after wrangler failed to do so with the same error message The request is malformed: failed to decode id [code: 7400]

Steps to reproduce

Everything exactly like here https://developers.cloudflare.com/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai (the issue started at D1 part)

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

rozenmd commented 3 months ago

@ElvisAns did you add database_id = "abc-def-geh" instead of the real database_id?

ElvisAns commented 3 months ago

yes @rozenmd and it was exactly the same as in the tutorial database_id = "abc-def-geh" ... Also, later I knew that local development needed preview_database_id and added it by finding it via wrangler d1 list.

rozenmd commented 3 months ago

Do you have it working now with a real database_id?

ElvisAns commented 3 months ago

Nope, whenever i add the --remote flag, it doesn't work

rozenmd commented 3 months ago

Can you paste your wrangler.toml's d1_databases section?

ElvisAns commented 3 months ago
[[d1_databases]]
binding = "DB" # available in your Worker on env.DB
database_name = "database"
database_id = "abc-def-geh"
preview_database_id = "7238f95d-3769-4616-8f45-xxxxxxxxxx"
rozenmd commented 3 months ago

database_id needs to be a real database_id if you want to use a remote database preview_database_id only needs to be a real database_id if you run --preview --remote

ElvisAns commented 3 months ago

Okay, you are right! you are absolutely right and this is definitely not a bug. I have replaced database_id with the real db id and it works however this should be clear in the documentation. Any way, how does wrangler handle local database under the hood? Should i create two separate db on CF dashboard then use their id in preview and another for prod?