OK, I Have a working solution but I don' t think it's very pretty.  It
appears Alberto was right about the rules being optimized if they could
be determined statically.  I didn't detect that earlier though because
the func_original function wasn't returning the correct function.
Anyhow.. here is how this works.

1) Patch TG to user MultiorderGenericFunction
 I got an ambiguous function def error when I tried it with stock TG.
Index: turbogears/database.py
===================================================================
--- turbogears/database.py      (revision 2078)
+++ turbogears/database.py      (working copy)
@@ -13,6 +13,7 @@

 import turbogears
 from turbogears import config, errorhandling
+from turbogears.genericfunctions import MultiorderGenericFunction

 log = logging.getLogger("turbogears.database")

@@ -231,7 +232,7 @@
     for hub in hub_registry:
         hub.end()

-[dispatch.generic()]
+[dispatch.generic(MultiorderGenericFunction)]
 def run_with_transaction(func, *args, **kw):
     pass


2) Create a no_transaction decorator
from turbogears.decorator import weak_signature_decorator

def no_transaction():
        def wrap(func):
                def no_trans(func,*args,**kw):
                        cherrypy.request._no_trans=True
                        return func(*args,**kw)
                return no_trans
        return weak_signature_decorator(wrap)

3) create the test method for no_trans
  This has to be in a method for the reasons stated at the top of the
post.
def is_no_trans():
        return getattr(cherrypy.request,'_no_trans',False)

4) create the no trans method.  Order=-1 is important so you go before
the default sa_rwt, and so_rwt conditions.
@run_with_transaction.when("is_no_trans()",order=-1)
def _no_trans_for_this_method(func, *args, **kw):
        log.debug ( "No Trans Method" )
        return func(*args, **kw)


5) In your controller code you can now decorate like this:
@no_transaction()
@expose()
def something(self): pass

Note that order is indeed important for no_transaction because the
request attribute must be set before it is tested for in the expose
method.


Well, this has been a long thread.  This solution works for me but I'm
not sure it's very suited to suggest to others in the same boat.
Anyone have a better solution?

-Dennis


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to