What's the purpose of `TransactionRead` in official Python bindings


(Amirouche) #1

What’s the purpose of the TransactionRead class in the Python bindings. I see it’s used to both in transactional and in Transaction as Transaction.snapshot property. My understanding is that TransactionRead is useful to do snapshot reads.

  • Does it make sens to create a TransactionRead alone?
  • Does TransactionSnapshotRead or TransactionSnapshot better explain its purpose?

I am working on asyncio bindings.

(Alec Grieser) #2

The purpose of the TransactionRead class is to encapsulate all of the parts of a transaction that lets it read from the database. (The equivalent in Java, for example, is the ReadTransaction interface, which arguably a better name.) As it turns out, because in snapshot isolation, all a transaction can do is read, the Transaction.snapshot property only needs to be of that type.

In a language with static type checking, it’s useful to have a ReadTransaction interface so that methods can declare that they will be doing some reads (but no writes) and have the type checker enforce that. In Python, the need is probably less (because of duck typing), but it’s still nice for code re-use reasons. Given that it handles both snapshot and non-snapsho reads, probably putting snapshot in the name would be confusing.

(Amirouche) #3

I am not sure either, right now I call that class BaseTransaction.

By the way, I pushed my proof of concept bindings that seem to work.