[Z3-sqlos] [PATCH] Use a Transaction per thread, rather than a Connection

Andrew Bennetts andrew-sqlos at puzzling.org
Wed Oct 6 14:59:05 CEST 2004


Hi all,

I've got a patch I'd like to commit, as it fixes some problems we're having
with SQLOS at Canonical.  The symptoms we've noticed are:
    - changes to the database from outside Zope not being visible in Zope,
      unless we restart Zope.
    - RelatedJoins -- changes made with addFoo/removeFoo methods generated
      by RelatedJoins aren't committed, because the SQLObject has no objects 
      to register as dirty in this case.

Using an sqlobject.dbconnection.Transaction per thread, rather than a
Connection, seems to fix these issues and feels like a better match for the
Zope model of "each web request runs in its own thread and its own
transaction".

Thus, I'd like to commit this patch:

--- orig/connection.py
+++ mod/connection.py
@@ -90,7 +90,7 @@
                 warnings.warn("Couldn't find a rdb connection by the "
                               "name %s. Please verify your setup." % name,
                               SQLObjectWarning, 3)
-            connCache[key] = IZopeSQLConnection(newconn())
+            connCache[key] = IZopeSQLConnection(newconn()).transaction()
         return connCache[key]
 
     def releaseConnection(name):


Although it's a small patch, it's a pretty low-level change, so I'm asking
for feedback before just doing it and accidentally breaking someone's code
:)

-Andrew.




More information about the z3-sqlos mailing list