[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

daklib/archive.py commit finally vs except



Hi,

Lately I've been reading dak's code in my free time (which isn't much in this
time of year), and today I've come across the ArchiveTransaction commit code:

def commit(self):
	"""commit changes"""
	try:
		self.session.commit()
		self.fs.commit()
	finally:
		self.session.rollback()
		self.fs.rollback()

So, the finally gets executed regardless if there is an exception in the try
block or not, which would mean that this block is always doing a rollback (I
haven't followed the session and fs code), I think the intended code would be:
	
	try:
		self.session.commit()
		self.fs.commit()
	except:
		self.session.rollback()
		self.fs.rollback()
		raise

Also if session and fs are locking some resource it would be better to reorder
them (and make sure that other accesses use the same order and the inverse
unlock order):

	try:
		self.session.commit()
		self.fs.commit()
	except:
		self.fs.rollback()
		self.session.rollback()
		raise

And, in general, plain except are frown upon, so it might be better:

	except BaseException:

Please, correct me if I'm wrong or missing some other parts.

Happy hacking,
-- 
"It is not the task of the University to offer what society asks for, but to
give what society needs."
-- Edsger W. Dijkstra
Saludos /\/\ /\ >< `/

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: