fix for bug with hid starting at 2 instead of 1, introduced by myself at 2bb7df0

This commit is contained in:
Martin Cech
2014-01-03 16:01:54 -05:00
parent 458c68985d
commit 1c5408ab0c
+10 -5
View File
@@ -1852,16 +1852,21 @@ class_mapper(model.LibraryDatasetDatasetAssociation).add_property( "creating_job
def db_next_hid( self ):
"""
Override __next_hid to generate from the database in a concurrency
safe way.
db_next_hid( self )
Override __next_hid to generate from the database in a concurrency safe way.
Loads the next history ID from the DB and returns it.
It also saves the future next_id into the DB.
:rtype: int
:returns: the next history id
"""
conn = object_session( self ).connection()
table = self.table
trans = conn.begin()
try:
current_hid = select( [table.c.hid_counter], table.c.id == self.id, for_update=True ).scalar()
next_hid = current_hid + 1
table.update( table.c.id == self.id ).execute( hid_counter = ( next_hid ) )
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 + 1 ) )
trans.commit()
return next_hid
except: