How to keep single session with reopening connections? #12209
-
|
Hi there! P.S. Please forgive me if my wording seems strange. Please look at the code: It reproduces the output: As you could see sessions at each How could I make session be the same but at the same time close connection each I mean calling As you could guess I need a single session objects during some time (f.e. web request). Thanks in advance and happy new year! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
the ORM Session used to support this directly through a feature called "autocommit" mode, we later named this to "library level autocommit mode" to clarify its difference from the driver level autocommit that you're using above. This mode was deprecated in the 1.4 series of SQLAlchemy and removed in 2.0. It basically led to code that created lots of connections and these connections were continuously having rollback/commit called on them, which performs poorly and also led to more deadlocks and transactional consistency issues. there might be ways to rig a |
Beta Was this translation helpful? Give feedback.
the ORM Session used to support this directly through a feature called "autocommit" mode, we later named this to "library level autocommit mode" to clarify its difference from the driver level autocommit that you're using above. This mode was deprecated in the 1.4 series of SQLAlchemy and removed in 2.0. It basically led to code that created lots of connections and these connections were continuously having rollback/commit called on them, which performs poorly and also led to more deadlocks and transactional consistency issues.
there might be ways to rig a
Sessionwith events to sort of act in this way again but if you are using driver level autocommit with PostgreSQL, the connections won…