Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aiohttp: get current running app

Currently I'm doing the following to get the current running app

async def handler(request):
    app = request.app

Isn't there another way for getting the current running app? Consider the below snippet (the default for author_id):

class Comment(DeclarativeBase):
    author_id = Column(Integer, ForeignKey('member.id'), default=Member.current_logged_in()) 

class Member(DeclarativeBase):
    @classmethod
    def current_logged_in()
        pass

As the session is kept in the current running app and as you can see it is only accessible from the incoming request, how can I get the current running app to use the session for determining the current_logged_in user and thus be used as the default value for Comment's author_id? I wish I have made my point.

like image 318
Juggernaut Avatar asked Jul 08 '26 12:07

Juggernaut


1 Answers

Right now there is no implicit context for aiohttp application.

BTW don't do synchronous calls (SQLAlchemy ORM in your case) from aiohttp code.

like image 64
Andrew Svetlov Avatar answered Jul 11 '26 03:07

Andrew Svetlov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!