0

I have the following code in my Telegram bot:

async def approve_or_disapprove(user_id):
    @dp.callback_query_handler(text="approve")
    async def approve_transaction(call: types.CallbackQuery):
        with engine.connect() as connection:
            users = variables.tables["users"]
            stmt = users.update().where(users.c.user_id == f"{user_id}").values(if_paid = "y")
            connection.execute(stmt)

However, at line "connection.execute(stmt)" I receive an error "ResourceClosedError: This Connection is closed". I have tried closing all the existing connections in the code explicitly, however, it didn't work. I am using:

Python 3.11.3 
SQLAlchemy 2.0.15 
PostgreSQL 15.2

As far as I got from the Internet, this error shouldn't occur in postgres since multiple connections are possible. What am I doing wrong? Ready to provide additional data if needed.

Anna
  • 101
  • 8
  • After a day of figuring out what's going wrong I managed to determine that this error occurs only when you do a line-by-line debugging. I don't know what exactly happens to the connection at this point, so I would be grateful for documentation references or direct answers. – Anna Jun 11 '23 at 11:17

0 Answers0