> That didn't seem to affect anything. I also put a log statement in the
> condition and turned the logging level to debug. I noticed that
> conditions seem to be evaluated at load time.
Not exactly. As I understand RD's implementation, Conditions are
"compiled" at load time but are evaluated on each call to the generic
function (else there'll be no fun ;)
> I thought then that
> perhaps the _no_trans attribute is not being set until after the
> condition is evaluated:
>
> example:
> @expose()
> def something(self):
> pass
> something._no_trans=True
>
> is the same as
> def something(self):
> pass
> expose()(something)
> something._no_trans=True
Aha! I think I now know where the problem is :) Try this:
something = expose()(something) # don't forget resetting the attribute
something._no_trans = True
If this works tell me as the solution could be optimized....
> I tried patching TG for the MultiorderGenericFunction in combination
> with the change I mentioned above and the sa_rwt method is still
> called. I'm a little stumpted at this point. The condition is indeed
> being evaluated (I checked that with the logging) but I haven't been
> able to figure out what I need to change to get run_with_transaction to
> call my no_trans method instead of sa_rwt.
I believe the problem is that the "func" the conditions are checking is
the un-decorated function which hasn't got the _no_trans attribute you're
adding as the @ syntax decorates the function before you have a chance to
set the attr.
The best way yo implement this IMO would be to write a decorator that sets
this attribute in the *original* function and check for this attribute on
the *original* function in the condition. Something like:
form turbogears.decorator import func_original
def no_transaction(func):
func_original(func)._no_trans = True
return func
@run_with_transaction.when("_use_sa() and getattr(func_original(func),
'_no_trans', False)")
def _no_trans_for_me(func, *args, **kw):
return func(*args, **kw)
now you should (I hope) be able to decorate any method which you don't
want a transaction to begin/end when called with "no_transaction"
@no_transaction
@expose()
def foo(self, bar):
....
You *should* be able to stack "no_transaction" in any order....
Tell me how it goes...
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---