Fork me on GitHub
#xtdb
<
2022-12-17
>
Hukka09:12:57

Transaction docs say what happens when transaction functions return false or a list of new operations, with a note that they should return a list or false. https://github.com/xtdb/xtdb/blob/master/test/test/xtdb/tx_test.clj shows that actually nil is also tested for, but is this something that might change in the future? And finally, returning true is not tested at all so I suppose it really is undefined behaviour. But it seems counterintuitive that transaction functions that work purely as pre-conditions need to return nil/false, and that they mean the opposite thing. Usually nil would be either unacceptable or be considered falsy. And it's also counterintuitive, that boolean is not a valid return type when false is.

Hukka09:12:18

My first thoughts would be that nil should raise an error, to avoid treating mistakes as explicit results, and the valid return types would be booleans and seqs (or vectors, but list seems just wrong since very few things actually return lists), with true meaning just continue, false to abort, and the seq to add more processing.

Hukka09:12:07

Of course at this point changing what nil does would be a pretty bad breaking change, even if it was never documented…

tatut05:12:45

nil is the empty list, so it makes sense to me that it means empty transactions

tatut05:12:33

then you can do things like (when (some-condition-query ctx) [[:xtdb.api/put …]]) in tx functions, if condition doesn’t match tx does nothing