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/d76d421e-d268-4385-8fac-10d9a7089296n%40googlegroups.com.