A small gotcha and a proposed fix

goran at krampe.se goran at krampe.se
Wed Mar 22 07:15:48 UTC 2006


Hi Chris and folks!

With the current implementation of MagmaSession>>commit: you can make an
"early exit" and miss the actual commit like this:

session commit: [
	^mObject foo: 3]

Which will set foo to 3 and then return the result of that -
unfortunately missing the actual commit in MagmaSession>>commit: since
that code looks like this:

commit: aBlock

	| result |
	self begin.
	result := aBlock value.
	self commit.
	^result
 
Since Magma "supports" nested transactions (it just keeps a nest level
count and the actual commit occurs when you are all the way back out -
so it all turns into a BIG commit - fair enough) the effect is that you
now are one level down and subsequent calls to commit: will of course
not do anything. And yes - it was a bit painful to figure that stupid
thing out. :)

Better would probably be:

commit: aBlock

	self begin.
	^[aBlock value]
		ensure: [self commit]

If there is an error in "self begin" we don't try to commit but if
"aBlock value" returns we don't miss the commit.

regards, Göran


More information about the Magma mailing list