1) it is responsibility of the database to guarantee data integrity,
The validation process is there only to try notify the user that
something is wrong. The validation cannot check all possible cases
before the record goes in the database without locking the database
thus having no concurrency. To do database validation just set the
field attribute to "unique" along with IS_NOT_IN_DB().
2) since accepts(...,session,...) prevents double form submission
this is very unlikely to happen anyway. A lock of any kind would slow
down everything in order to take care of a very rare event.
3) Nothing prevents the use from locking himself using (for example)
cache.locker.acquire() and cache.locker.release().
I do not believe IS_NOT_IN_DB() needs to be changed.
Massimo
validation checks and database integrity checks and not the same
thing. Not all input comes from forms and form validation is not
always the same (for example forms may be validated in a user
dependent basis). Thus collapsing form validation with database
integrity checks is not a good idea because it would not increase but
decrease functionality. I agree it would be nice to have a way to
capture database errors and explain them to the user but this is not
technically possible because: 1) the database API only raises
OperationalError and there is no way for web2py to know if this is a
database integrity problem or not; 2) the database insert may not be
performed by a form.accepts.
Let me reiterate that this is not a problem, this how all frameworks
handle it and it cannot cause data integrity problems. The worst case
scenario is that the user gets a ticket (and the event is so rare
that you should not worry about it, it is going to be less common
that tickets caused by network problems).
You can also do
try: r=form.accepts(request.vars)
except OperationalError:
form.errors['fieldname']='database problem, perhaps this
value is already in db'
r=False
which is very close to what you asked.
Massimo
PS. Sorry my emails are out of order but I have been out of town with
spotty connection.
Please show me any framework that does not have this problem and does
not serializes database access.
Massimo