zzzeek / test_sqlalchemy

0 stars 0 forks source link

Consider adding an is_active property to the session #976

Closed sqlalchemy-bot closed 15 years ago

sqlalchemy-bot commented 16 years ago

Issue created by Anonymous


Since committing an inactive session raises an error in SA 0.4.3, it would be helpful to have a property that tells whether the session is active or not. This property should simply query the same property of the corresponding transaction.

A use case for this is TurboGears. See also my request on the SA mailing list.


Attachments: scoping.patch

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


Ok, we're using ScopedSession().is_active now in TG, this works with SA 0.4.7. Can you apply the patch above anyway? I think that would be a bit nicer and maybe faster.

TG wraps every controller method in a transaction with begin() and commit(), but since somebody might have already committed inside the transaction, it checks whether the transaction is still active before the final commit.

sqlalchemy-bot commented 10 years ago

Michael Bayer (zzzeek) wrote:


Removing milestone: 0.4.xx (automated comment)

sqlalchemy-bot commented 15 years ago

Michael Bayer (zzzeek) wrote:


2f19d81a087a65af9ba2e20bdfbe39ee8c52aa11 f80471e6f385739ee23b96dfe4aa3a48fbc8e1fd

sqlalchemy-bot commented 15 years ago

Michael Bayer (zzzeek) wrote:


this is approved; I'd like to add it to 0.4 and 0.5.

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


MyScopedSession().is_active is an immediate workaround for now.

Just to be clear, TurboGears is calling begin() in one particular block of code somewhere, and then commit() in some totally different block of code ? That's not a spectacular pattern in the first place is there an issue just using the format above ?

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


Thanks for implementing this. To make this useful for TurboGears, the property should also be available in a scoped session (see patch).

sqlalchemy-bot commented 15 years ago

Anonymous wrote:


Thanks; this is now used in [http://trac.turbogears.org/changeset/5997 TG 6b7cbe6d252f6e86e7d3f568f7e6c04e68743ddf.

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


Make is_active property available in scoped session

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


im not correct on that point. subtransactions, when rolled back, leave the session in a "not active" state. This most frequently occurs when a flush() fails, for example.

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


c1363d8aca5623114d36445df4c95b6bc5b49ccb b5261fa1fb338efbbf83fb600516f183de247a58 . But note that this flag is always True with a transactional (in 0.5 an autocommit) session, since a new transaction is begun automatically on commit/rollback in that case.

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


sqlalchemy-bot commented 10 years ago

Changes by Michael Bayer (zzzeek): removed "0.4.xx" milestone

sqlalchemy-bot commented 15 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): changed milestone from "0.4.7" to "0.4.xx"

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: removed "resolved" state

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: set attachment to "scoping.patch"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): changed kind from "bug" to "enhancement"; changed component from "(none)" to "orm"; set milestone to "0.4.4"