why does query invoke a transaction
See original GitHub issuemysqlclient==1.4.2.post1 SQLAlchemy==1.3.5
def test4():
Session = db.session # db.session = sessionmaker(bind=self.engine, **session_options)
print("start")
print(db.status())
conn = db.engine.connect()
print(db.status())
print("after check out one connection")
session = Session(bind=conn)
new_user = User()
new_user.id = 3
print("begin the transaction")
session.query(User).filter_by(id=1).first()
# session.rollback() # uncomment this line. everything works fine
print("invalidate the connection. mock the connection not available")
conn.invalidate()
print(db.status())
session.query(User).filter_by(id=1).first()
print(db.status())
this will generate exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1177, in _execute_context
conn = self._revalidate_connection()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 463, in _revalidate_connection
"Can't reconnect until invalid "
sqlalchemy.exc.InvalidRequestError: Can't reconnect until invalid transaction is rolled back
After this, this connection is no longer usable anymore.
My question is :
Why does query invoke a transaction?
Normally speaking, if there is no transaction, conn.invalidate()
won’t cause any problems. It just close the connection and return it back to pools, right? For example, if add session.rollback()
right after query, everything works just fine.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Chaincode Invoke and Query. Overview | by KC Tam - Medium
Chaincode function invoke is a transaction reflecting a real business transaction. A quick example is that Alice sends Bob 100 shares.
Read more >Understanding SQL Server query execution and transactions
Since SQL Server default transaction mode is Autocommit Transactions, each individual statement is a transaction.
Read more >Incomplete transaction may hold large number of locks and ...
When a transaction is not completed either because a query times out or because the batch is cancelled in the middle of a...
Read more >Transactions - Snowflake Documentation
The term “query statement” refers to SELECT and CALL statements. Although a CALL statement (which calls a stored procedure) is a single statement,...
Read more >How to use transactions in Microsoft Access VBA - Codekabinett
The implementation is fairly simple. Before you execute the first action query, you instruct the DBEngine to start a transaction using the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thx, @zzzeek. I just became your patron. Really worth all detailed answers
closing this for now.