Skip to content

Fix durable-objects routing for list IDs that contain "add" - #109

Closed
RaphaelFakhri wants to merge 1 commit into
cloudflare:mainfrom
RaphaelFakhri:fix-durable-objects-routing
Closed

RaphaelFakhri wants to merge 1 commit into
cloudflare:mainfrom
RaphaelFakhri:fix-durable-objects-routing

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

The durable-objects example picks a route with substring checks ("/add" in url.path, "/show" in url.path). Any path that contains /add anywhere is treated as an add request, even when the action is show.

For example, GET /address-book/show takes the add branch, reads url.path.split("/")[3], raises IndexError, and returns HTTP 500 instead of No messages. GET /room-1/add without a message fails the same way.

This change matches the action path segment exactly:

  • /<list_id>/add/<message> adds a message.
  • /<list_id>/show shows messages.
  • Anything else, including /<list_id>/add without a message, returns 404.

Testing

test_durable_objects now also requests /address-book/show and /room-1/add.

uv run pytest -q tests/test_examples.py -k test_durable_objects
  • Before the fix: 1 failed (assert 500 == 200 at the /address-book/show request).
  • After the fix: 1 passed.

uv run ruff check . and uv run ruff format --check pass.

The example matched routes with substring checks such as "/add" in url.path, so GET /address-book/show was handled as an add request and failed with an IndexError (HTTP 500). Match the action path segment exactly instead, and return 404 for /<list_id>/add without a message.
@ryanking13

Copy link
Copy Markdown
Contributor

Looks like this PR is doing the same thing with (#110). I merged that one.

@ryanking13 ryanking13 closed this Oct 26, 2026
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.

2 participants