Skip to content

Cannot use subapps with overlapped prefixes #3701

Closed
@Mirraz

Description

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

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions