def db_next_hid(self, n=1):
 conn = object_session(self).connection()
 table = self.table
 trans = conn.begin()
 try:
  next_hid = select([table.c.hid_counter], (table.c.id == self.id), for_update=True).scalar()
  table.update((table.c.id == self.id)).execute(hid_counter=(next_hid + n))
  trans.commit()
  return next_hid
 except:
  trans.rollback()
  raise

def db_next_hid ( self , n = 1 ) : conn = object_session ( self ) . connection ( ) table = self . table trans = conn . begin ( ) try : next_hid = select ( [ table . c . hid_counter ] , ( table . c . id == self . id ) , for_update = True ) . scalar ( ) table . update ( ( table . c . id == self . id ) ) . execute ( hid_counter = ( next_hid + n ) ) trans . commit ( ) return next_hid except : trans . rollback ( ) raise
db_next_hid override __next_hid to generate from the database in a concurrency safe way .