Skip to content

durable-objects: route on the action segment, not a substring of the path - #110

Merged
ryanking13 merged 1 commit into
cloudflare:mainfrom
bercedev:durable-objects-routing
Oct 26, 2026
Merged

ryanking13 merged 1 commit into
cloudflare:mainfrom
bercedev:durable-objects-routing

Conversation

@bercedev

Copy link
Copy Markdown

Fixes #108

durable-objects/src/entry.py picked the branch with "/add" in url.path and "/show" in url.path. So a list ID that contains /add, such as /address-book/show, took the add branch and failed with IndexError on url.path.split("/")[3], and /room-1/add without a message failed the same way.

The handler now splits the path once into list ID, action and message, and compares the action exactly (add / show). An add without a message gets the same 400 usage text as a request without a list ID. Unknown actions still get 404.

I didn't run it under pywrangler dev. I loaded entry.py with stub workers and pyodide.ffi modules and an in-memory storage, then called Default.fetch:

Path Before After
/address-book/show IndexError 200 No messages
/address-book/add/hi 200 Message sent 200 Message sent
/address-book/show (after the add) IndexError 200 hi
/room-1/add IndexError 400 usage
/room-1/show 200 No messages 200 No messages
/ 400 usage 400 usage
/x/other 404 404

ruff 0.16.8 (check and format) and codespell 2.4.3 from the pre-commit config are clean.

Note: I used Claude Code while working on this.

…path

A list ID starting with "add" or "show" matched the wrong branch, and /<list_id>/add without a message raised IndexError. Split the path into list ID, action and message, compare the action exactly, and answer an add without a message with the usage text. Fixes cloudflare#108.
@ryanking13
ryanking13 merged commit 51000e6 into cloudflare:main Oct 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

durable-objects example returns 500 for list IDs that contain "add"

2 participants