Changing state of started or joined application is deprecated....grrrr #1947
Description
Long story short
I very often want to set items on "frozen" app. I'm getting depreciation warnings for this and in future (presumably) this will fail outright. This is very frustrating.
This is made worse by pytest 3.1 which prints all warnings making this harder to ignore.
Expected behaviour
app['database'] = await create_my_database(...)In a startup function should not cause deprecation warnings.
Actual behaviour
I'm getting warnings in lots of setups which I would have thought sensible.
Examples
in unit tests setting up a secondary server:
@pytest.fixture
def mock_external_server(loop, test_server):
app = Application()
app.router.add_post('/whatever.json', handler)
server = loop.run_until_complete(test_server(app))
app['server_name'] = f'http://localhost:{server.port}'
return serverThis causes a warning because I'm setting the server_name item on an app which is started.
using startup function:
async def startup(app: web.Application):
app['pg_engine'] = await create_engine(pg_dsn(app['database']), loop=app.loop)
...
app = web.Application()
app.on_startup.append(startup)(real life example here)
This again causes warnings setting pg_engine in a startup script.
Workaround
Surely this warning is wrong? If not what workaround should I use?
The only solution I can think of is an ugly bodge:
async def startup(app: web.Application):
app['data']['pg_engine'] = await create_engine(pg_dsn(app['database']), loop=app.loop)
...
app = web.Application(middlewares=middleware)
app['data'] = {}
app.on_startup.append(startup)