I'm looking for a reasonable answer to this question:
https://news.ycombinator.com/item?id=4207314
I have no doubt that if I dug into it then it would all make sense, but my first instinct is this: how much of this complexity (proxy objects to thread locals, context stacks etc) results from the fact that doing:from flask import requestis just a bad idea? Perhaps things would be easier if instead of:from flask import request ... @app.route('/'): def index(): return "Hello from %s" % request.args.get('name')we did:@app.route('/'): def index(request): return "Hello from %s" % request.args.get('name')
Armin's response the the above is not very satisfying:
I was a huge opponent of thread locals for a really long time but I finally had to acknowledge that they make things easier instead of harder.
...
The fact that you can do `_app_ctx_stack.top.mydatabase_connection` to get a database connection from anywhere is very helpful.
...
TL;DR: you can't live without thread locals or you have a horrible API.
I don't see how _app_ctx_stack.top.mydatabase_connection
is any better than request.app.my_database_connection
.