Wrap queries in transaction
This alleviates current locking issues where nothing gets written in production.
Related to T4228