Skip to content

web.Application and web_urldispatcher.UrlDispatcher can't be used separately #1373

Closed
@ikalnytskyi

Description

Long story short

Since aiohttp 1.1.0 there's no correct way to create web.Application and web_urldispatcher.UrlDispatcher separately, since the latest requires the former as argument and both saves each other as protected properties.

app = web.Application(
    router=web_urldispatcher.UrlDispatcher(app),  # app doesn't exist yet!
)

possible solutions is to patch protected property:

# either on router
app = web.Application(router=web_urldispatcher.UrlDispatcher(None))
app.router._app = app

# or on application
app = web.Application()
app._router = web_urldispatcher.UrlDispatcher(app)

aiohttp users can't rely on protected attributes, since they may changed from version to version.

Expected behaviour

There should be a proper way to resolve this solution.

Actual behaviour

Workaround is needed.

Steps to reproduce

  • Create web_urldispatcher.UrlDispatcher independently and pass it to web.Application.

Your environment

  • aiohttp 1.1.0
  • macOS sierra, Arch Linux

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions