Skip to content
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

Tokens filter mismatch error when routing #20

Closed
kszys opened this issue Nov 1, 2024 · 1 comment
Closed

Tokens filter mismatch error when routing #20

kszys opened this issue Nov 1, 2024 · 1 comment

Comments

@kszys
Copy link

kszys commented Nov 1, 2024

I ran into some issues with routing, and I am not sure I am doing something wrong, or this is an expected behaviour...

I am trying to define a catch-all route in py4web that will handle things not handled by any other route. Here a minimal code example:

# __init__.py
from py4web import action

@action('index')
@action('<project_id:int>')
def index(project_id=None):
    return f"Index: (project_id={project_id})"

@action('<anything:path>')
def catch_all(anything):
    return f"Catch-all: {anything}"

If I try to access the application with some random URL, I get a pretty extensive traceback with the main error message being:

ombott.router.radidict.RadiDictKeyError: tokens filter mismatch

The problem is reported while processing the:

@action('<anything:path>')

Not sure, if what I try is not valid or otherwise wrong, or it is a bug in Ombott?

@kszys
Copy link
Author

kszys commented Nov 1, 2024

Here is an answer I got from Val K elsewhere:

Hi!
Short story: try to add static prefix to the first route: @action('projects/<project_id:int>')

Long story: ombott uses radix-tree hybrid router, it is declaration-order-independent and instead of order-dependent resolving it prioritizes static route-fragment over dynamic one, since this is most expected behavior.
So this solution has some constraints - you can not have 2 (or more) routes that have dynamic fragment of different types (int, path) in the same place.

Hence the behaviour is expected and it is a documentation issue rather than a bug. I submitted a PR (web2py/py4web#938) to improve the documentation, and I am closing this issue.

@kszys kszys closed this as completed Nov 1, 2024
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

No branches or pull requests

1 participant