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.