+1 for bug.

On 12/12/06, Alberto Valverde <[EMAIL PROTECTED]> wrote:
>
>
> On Dec 11, 2006, at 11:37 PM, Dennis Muhlestein wrote:
>
> >
> >
> >>> -Dennis run_with_transaction is a generic function you can
> >>> specialize to fit
> >> your needs, for example:
> >>
> >> from turbogears.database import run_with_transaction, _use_sa
> >>
> >> @run_with_transaction.when("getattr(func, '_no_trans', False) and
> >> _use_sa()")
> >> def _no_trans_for_this_method(func, *args, **kw):
> >>         return func(*args, **kw)
> >>
> >> Now in any controller method you can set a _no_trans attribute to
> >> True so this specialized version which doesn't start a session or
> >> begins any transaction runs when run_with_transaction is called:
> >>
> >
> > This is a nice approach to this problem.  I learned how generic
> > functions work and checked out how run_with_transaction is implemented
> > using that concept.
> >
> > There is one issue though, when using the approach mentioned, my
> > _no_trans_ method still isn't called.  The _use_sa() function returns
> > another the sa_rwt method because it evaluates to true before this
> > rule
> > is evaluated.  I see an implementation for Ordered generic
> > functions in
> > the genericfunctions.py file but that method is not being used by
> > run_with_transaction.
> >
> > If I could call:
> >
> > @run_with_transaction("getattr(func,"_no_trans",False) and
> > _use_sa()",order=0)
> >
> > Then this would work I believe.
> >
> > Should TG be patched to handle this or am I missing something?
> > Thanks
>
> That should have worked (unless I'm missing something) because the
> rule that I wrote in the example that checks for _use_sa() *and*
> getattr(...) is more specific than _use_sa() by itself, however, for
> some strange reason (at least strange to me) it seems it doesn't
> work. Have you tried swapping the predicates?
>
> """_use_sa() and getattr(func,"_no_trans",False)"""
>
> If that still doesn't make it, fortunately, as you've noticed, TG has
> the infrastruture to handle the "order" argument to the
> GenericFunction decorators. You'll need to patch
> database.run_with_transaction so it looks like this:
>
> from turbogears.genericfunctions import MultiorderGenericFunction
>
> @generic(MultiorderGenericFunction)
> def run_with_transaction(....)
>
> You'll need to set the order to -1 so it runs before the default
> which is 0.
>
> If this solution works and all tests pass you could submit a ticket
> with the patch so we can commit it.
>
> However, TG 1.0 is in a feature-freeze standstill, so the dilema is:
> is this a new feature or a bug fix? I'd consider it a "bug" because
> the fact that "run_with_transaction" is a generic function suggests
> that the kind of thing you're trying to do should be possible... I
> have no problem in comitting it if it doesn't break anything. Opinions?
>
> Alberto
>
>
>
> >
>


-- 
cheers
    elvelind grandin

--~--~---------~--~----~------------~-------~--~----~
 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