Consider adding an is_active property to the session

Issue #976 resolved
Former user created an issue

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.

Comments (11)

  1. Mike Bayer repo owner

    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.

  2. Former user Account Deleted
    • removed status
    • changed status to open

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

  3. Mike Bayer repo owner

    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 ?

  4. Former user Account Deleted

    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.

  5. Log in to comment