On 3/26/07, Jesse James <[EMAIL PROTECTED]> wrote:
> did you mean 'transaction' when you said 'session' below?
> Also, did you ever get a concise clear set of mods to apply to turn
> off auto-transactions?
The solution was that run_with_transaction is a generic function. You
can add a rule and a function to make it do certain things depending
on criteria.
here is what I did.
1) Create a wrapper function that sets an attribute on a function
telling it NOT to use run_with_transaction
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)
def is_no_trans():
return getattr(cherrypy.request,'_no_trans',False)
2) create an alternate function to run instead of run_with_transaction:
@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)
3) In your code, you just need to use your new decorator:
@no_transation()
@expose()
def etc...etc...
A note: The order of the decorator is important. You have to put it
before expose. That is because I used the cherrypy.request attribute.
There may be a way to do it that doesn't worry about the order but
this method is working for me.
-Dennis
> I'm trying to do the same (sqlalchemy user) and have found this thread
> quite difficult to follow completely to a conclusion of any kind.
> thanks,
> Joel
>
> On Dec 6 2006, 11:40 am, "Dennis Muhlestein" <[EMAIL PROTECTED]>
> wrote:
> > This is more of a best practice question:
> >
> > I find having the framework manage the database session for you OK 95%
> > of the time. What do you do in the other 5% of the time?
> >
> > Example 1: I have certain credit card processing methods that require
> > commits to the database before and after the card is processed.
> > Example 2: I have some methods that require no database interaction.
> > (So why create a session? .. also.. how much overhead is there in
> > creating the session?)
> >
> > Anyone have any best practice ideas for situations like this?
> >
> > Here is what I did on previous websites:
> > Background:
> > 1- When I 1st started Using SQLa, TG had no support for it but it
> > worked great by manually managing it.
> > 2- SQLalchemy support didn't work with TG.run_with_transaction for a
> > time when SQLA moved to version 2.x
> > Solutions:
> > 1-Manually manage SQLAlchemy transations
> > 2-Hack TG in my start script to avoid run_with_transaction altogether:
> >
> > ==snip==
> > # hack for sa 0.2.x
> > def nothing(func,*args,**kw):
> > return func(*args,**kw)
> > turbogears.database.run_with_transaction=nothing
> > ==end snip==
> >
> > Anyway, I'm doing some new work and it would be the perfect time to get
> > rid of that hack but I don't have a real good solution for the 2
> > scenarios I mentioned above.
> >
> > Thoughts?
> > -Dennis
>
>
--
You can see what's happening at http://muhlesteins.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---