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

Cannot use subapps with overlapped prefixes #3701

Open
Mirraz opened this issue Apr 17, 2019 · 5 comments

Comments

@Mirraz
Copy link

commented Apr 17, 2019

Long story short

If I add to main app one subapp with prefix "/qwe/" and then add another subapp with prefix "/qwerty/" then routing to second subapp does not work. But if I firstly add subapp with prefix "/qwerty/" and then subapp with prefix "/qwe/" then everything works fine. See example.

Steps to reproduce

from aiohttp.web import Application, json_response, run_app


def create_subapp01():
    app = Application()
    app.router.add_route('GET', r'/aaa', lambda req: json_response({'subapp01': 'aaa'}))
    return app


def create_subapp02():
    app = Application()
    app.router.add_route('GET', r'/aaa', lambda req: json_response({'subapp02': 'aaa'}))
    return app


def create_app():
    app = Application()

    app.add_subapp('/qwe/', create_subapp01())
    app.add_subapp('/qwerty/', create_subapp02())
    # GET /qwerty/aaa -> HTTP code 404

    # app.add_subapp('/qwerty/', create_subapp02())
    # app.add_subapp('/qwe/', create_subapp01())
    # GET /qwerty/aaa -> HTTP code 200

    return app


run_app(create_app(), host='127.0.0.1', port=8080)

Your environment

aiohttp 3.5.4

@asvetlov

This comment has been minimized.

Copy link
Member

commented Apr 17, 2019

This is by design: URL dispatcher handles all routes in the order of adding.
The same behavior is for overlapping routes in the application, not for sub-apps only.

Nothing to do here, the issue is not a bug

@asvetlov asvetlov closed this Apr 17, 2019

@asvetlov asvetlov added the invalid label Apr 17, 2019

@socketpair

This comment has been minimized.

Copy link
Contributor

commented Apr 17, 2019

@asvetlov what about slash ? if We add

app.add_subapp('/qwe/', create_subapp01())
app.add_subapp('/qwerty/', create_subapp02())

Why queries like /qwerty/asd match the first subapp ?

@asvetlov

This comment has been minimized.

Copy link
Member

commented Apr 17, 2019

Ah, I see. That's interesting.

@nikie

This comment has been minimized.

Copy link
Contributor

commented Apr 22, 2019

Hi,
Feels like a bug. I have just created PR #3708 which supposedly fixes it.
This is my first contribution, so please be picky and cautious :)

Eugene.

@asvetlov

This comment has been minimized.

Copy link
Member

commented Aug 30, 2019

Fixed by #3708

asvetlov added a commit that referenced this issue Aug 30, 2019
asvetlov added a commit that referenced this issue Aug 30, 2019
[3.6] Fix overshadowing of overlapped subapp prefixes (#3701). (#3708)
(cherry picked from commit 2aaf111)

Co-authored-by: Eugene Nikolaiev <eugene.nikolayev@gmail.com>
asvetlov added a commit that referenced this issue Aug 31, 2019
[3.6] Fix overshadowing of overlapped subapp prefixes (#3701). (#3708) (
#4027)

(cherry picked from commit 2aaf111)

Co-authored-by: Eugene Nikolaiev <eugene.nikolayev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.