[ZPatterns] TransactionAgents question

John Eikenberry jae-zpat@kavi.com
Thu, 13 Dec 2001 16:54:08 -0800


John Eikenberry wrote:

> A quick hack, but it shows the problem. The code in cause_error gets run
> twice. This would succeed if it was pop'd from the queue when run the first
> time.

It seems that this wasn't quite right... as just popping the erroring agent
off the queue will leave all the others to run. The correct behaviour (I
think) would be to remove all agents left in any queue's and re-raise the
error. 

Messing around a bit I found that if I try:except: the agent() calls in
runRuleAgents and friends, calling abort() in the except: and re-raising
the exception seems to be working pretty well. No problems yet. The unit
test below works with this change.

Could this be a solution? 

 
>     def testErrorRuleAgent(self):
>         """This test that rule agents handle exceptions, and
>            that they run in the order they were registered"""
>         l=[]
>         def cause_error(l=l):
>             l.append('done2')
>             raise "test"
>         get_transaction().registerRule(
>             lambda: l.append('done1'))
>         get_transaction().registerRule(
>             cause_error)
>         try:
>             get_transaction().commit(1)
>         except "test": pass
>         get_transaction().commit()
>         assert l==['done1','done2']
> 
> 
> 
> Steve Alexander wrote:
> 
> > John Eikenberry wrote:
> > 
> > > 
> > > The issue is that using ZedPatterns the above works, but the skinscript
> > > stays in the queue and gets called again on the final commit. This looks to
> > > be the result of TransactionAgent's method runRuleAgents(). Which runs all
> > > the agents in its queue, removing them from the queue after they've run.
> > > But if the agent raises an exception it never gets removed from the queue.
> > 
> > 
> > From your description, that sounds like a bug rather than a feature.
> > 
> > 
> > Can you tell me which of the TransactionAgents unit tests is testing the 
> >   wrong behaviour, or, if they do not cover the problem you're having, 
> > can you write an extra test or two that demonstrates the problem you're 
> > having.
> > 
> > Thanks.

-- 

John Eikenberry [jae@kavi.com]
______________________________________________________________
"A society that will trade a little liberty for a little order
 will deserve neither and lose both."
                                          --B. Franklin