Hello community/odoo sa,
I have the following issue :
Using an installation with 4 workers, I have a "web application" that uses XML RPC calls to create "calendar.event"
new Model('calendar.event').call('create', [{
'name' : session.partner.name,
'start': start.utc().format('YYYY-MM-DD HH:mm:ss'),
'stop': stop.utc().format('YYYY-MM-DD HH:mm:ss'),
'room_id': roomId,
'categ_ids': [[4, categ[1]]],
}]).fail(function(error) {
if(error.data.exception_type == "validation_error"){
Materialize.toast(error.data.arguments[0], 4000)
}
}).then(function (id) {
self.trigger_up('newEvent', {'id': id});
self.clearAll();
});
on my model I have a constraint function that checks if a room is already taken and in that case throw an Exception
@api.one
@api.constrains('room_id')
def _check_room_quota(self):
_logger.info('Check constraints _check_room_quota on record %s' % self.id)
if self.room_id :
# Prevent concurrent bookings
domain = [('room_id','=',self.room_id.id), ('start', '<', self.stop_datetime), ('stop', '>', self.start_datetime)]
conflicts_count = self.env['calendar.event'].sudo().with_context({'virtual_id': True}).search_count(domain)
if conflicts_count > 1:
raise ValidationError(_("Concurrent event detected - %s in %s") % (self.start_datetime, self.room_id.name))
This solution is working "most of the time", ie 99.9% of the time. Problem is once in a while, users achieve to create conflicting calendar.event.
I get into the sql.py code and my understanding is that the sql isolation should prevent this to happen :
In the context of a generic business data management software
such as OpenERP, we need the best guarantees that no data
corruption can ever be cause by simply running multiple
transactions in parallel. Therefore, the preferred level would
be the *serializable* level, which ensures that a set of
transactions is guaranteed to produce the same effect as
running them one at a time in some order.
But later
"OpenERP implements its own level of locking protection
for transactions that are highly likely to provoke concurrent
updates, such as stock reservations or document sequences updates.
Therefore we mostly care about the properties of snapshot isolation,
but we don't really need additional heuristics to trigger transaction
rollbacks, as we are taking care of triggering instant rollbacks
ourselves when it matters (and we can save the additional performance
hit of these heuristics)."
So I am a bit confused if I need to setup a specific locking protection or if I can rely on Odoo to prevent colliding updates and I miss something.
Many thanks for your input.
Jerome