[Zope] Re: Committing transaction by hand

Maciek Pasternacki maciekp at japhy.fnord.org
Sun Aug 8 18:16:09 EDT 2004


On Sweetmorn, Bureaucracy 2, 3170 YOLD, Dieter Maurer wrote:

>> ...
>>    get_transaction().commit()
>>    self.Cart().ThrowIn(self.REQUEST)
>>
>>It seems to work for now but I'm not really sure if such messing with
>>something usually done automagically by Zope won't have some obscure
>>and nasty side effects.  Am I doing something dangerous now or is this
>>the Right Way to deal with my problem and if it's not then what is?
>
> In general, it is not a good idea to explicitly commit a transaction:
>
>   If after the "commit" a "ConflictError" occurs (which is not
>   that unlikely when you modify the ZODB), then the
>   publisher will retry the requests.
>   This means that the transaction you already committed
>   is performed again.

In my case, if request is replayed exactly as if from the Web, it
shouldn't do any harm.  Before committing I leave `completion mark' in
session variables so that on next hit on the same URL application goes
directly to self.Cart().ThrowIn() (ThrowIn() gets all data from
SESSION and nothing directly from REQUEST), so either my data was
saved to SESSION, Cart() raises Unauthorized (or not) and
CookieCrumbler takes control (or not), or my data was not saved and it
gets created again from the same request, completion mark is saved,
this time successfully, code goes on to Cart(), and Unauthorized is
raised (or not).  In either case, data is either completed in SESSION,
marked as such and not touched again regardless of REQUEST, or it's
not there and REQUEST is processed once again beginning from state
identical to request start.

Please correct me if I'm wrong at some point or if there's some other
way to save data and let it survive an exception.

-- 
__    Maciek Pasternacki <maciekp at japhy.fnord.org> [ http://japhy.fnord.org/ ]
`| _   |_\  / { ...For I was born with a habit, from a sign,
,|{-}|}| }\/       the habit of a windswept thumb,
\/   |____/        and a sign of the rain... }                  ( Fish )  -><-



More information about the Zope mailing list