[Zope3-dev] Re: [ZODB-Dev] revise transaction API
Christian Theune
ct at gocept.com
Wed Mar 24 18:55:48 EST 2004
Howdi,
On Tue, 2004-03-16 at 20:37, Tim Peters wrote:
> [Christian Robottom Reis, on
> http://zope.org/Wikis/ZODB/ReviseTransactionAPI
> ]
> > I see this mentions savepoints for ZODB4. Can you tell me if you can
> > roll back to any savepoint in a running transaction's history?
>
> Yes, that's the idea.
>
> > If so, it would be a solution to that last (subtrasaction) problem I
> > posted about.
>
> That's why Jeremy worked on fleshing out these notes instead of replying
> specifically to that msg <wink>.
Ok, here some notes about one very annoying thing that I met several
times in the last couple of weeks:
There are times, when you want Zope to make the current request fail
(read: raise a Transaction). Take for example the authenticate() or
validate() method as known in Zope 2.
I have one implementation that made me get stuck as I wanted to count
how many false authentication requests (existing username, wrong
password) struck on an account.
The first way which obviously (well, it took me 15 minutes to remember
that rollbacks also apply to stuff I assign even if I wish it weren't
so) will fail: (read this as pseudocode)
...
if password != reference:
user.failures += 1
return 0
...
This can't work, as the exception that will get raisen forbids to store
the user.failures.
Lucky as I am, this application usees postgres for all data storage
anyway so, the code can be get to work (in the normal case) as follows:
...
if password != reference:
query("begin; update .... ; commit;")
return 0
...
This "kind of works", except when there are conflicts (or other
circumstances) that will make Zope rollback the transaction and retry.
So my question is: Is there a "standard" idiom one would use to
implement this, even if the data is not stored outside of the ZODB?
Christian
--
Christian Theune, gocept gmbh & co. kg
http://www.gocept.com - ct at gocept.com
fon: 03496 3099112 fax: 03496 3099118 mobile: 0179 7808366
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20040324/12ae9132/attachment.bin
More information about the ZODB-Dev
mailing list