Closed sqlalchemy-bot closed 15 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.
Michael Bayer (zzzeek) wrote:
2f19d81a087a65af9ba2e20bdfbe39ee8c52aa11 f80471e6f385739ee23b96dfe4aa3a48fbc8e1fd
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 ?
Anonymous wrote:
Thanks for implementing this. To make this useful for TurboGears, the property should also be available in a scoped session (see patch).
Anonymous wrote:
Thanks; this is now used in [http://trac.turbogears.org/changeset/5997 TG 6b7cbe6d252f6e86e7d3f568f7e6c04e68743ddf.
Anonymous wrote:
Make is_active property available in scoped session
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.
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.
Michael Bayer (zzzeek) wrote:
Changes by Michael Bayer (zzzeek): removed "0.4.xx" milestone
Changes by Michael Bayer (zzzeek): set state to "resolved"
Changes by Michael Bayer (zzzeek): changed milestone from "0.4.7" to "0.4.xx"
Changes by Anonymous: removed "resolved" state
Changes by Anonymous: set attachment to "scoping.patch"
Changes by Michael Bayer (zzzeek): set state to "resolved"
Changes by Michael Bayer (zzzeek): changed kind from "bug" to "enhancement"; changed component from "(none)" to "orm"; set milestone to "0.4.4"
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