I tried this, kept commit and close statements and removed dispose statement, but yet the problem is not solved, it's taking time to truncate the table.
On Wednesday, 14 December 2022 at 05:19:27 UTC+5:30 [email protected] wrote: > Is it possible your sessions hasn't committed the change / closed the > transaction? > > Also, I don't think dispose is helping you here. Consider removing it? > > How about modifying: > > def add_user(): > session = Session() > session.add(User(**{'user_id': 1, 'name': 'user name'})) > session.commit() > session.close() > # consider removing > # session.bind.dispose() > > > On Tuesday, December 13, 2022 at 8:13:14 AM UTC-5 [email protected] > wrote: > >> On creating all tables using alembic for migrations and then truncate any >> empty table gets completed quickly, BUT once lambda function is triggered >> to insert some data in a table through SQLAlchemy ORM Session query (as >> given below) and then truncate the table takes very much time. Where is the >> problem? >> >> ``` >> from sqlalchemy import create_engine >> from sqlalchemy.orm import sessionmaker >> >> engine = create_engine("mysql+pymysql://....") >> Session = sessionmaker(bind=engine) >> >> def add_user(): >> session = Session() >> session.add(User(**{'user_id': 1, 'name': 'user name'})) >> session.close() >> session.bind.dispose() >> >> ``` >> > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/f11abc11-9225-4325-9df7-9785c8843bfdn%40googlegroups.com.
