transactions

web3.py function get_block tranactions is not in the current block

web3.py function get_block tranactions is not in the current block Question: I want to synchronize all transactions with the database, so I use get_ Block method. The code is as follows: cur_block_num = web3.eth.get_block_number() if cur_block_num <= last_block_num: return res = web3.eth.get_block(cur_block_num, full_transactions=True) block_info = json.loads(web3.toJSON(res)) block_info = convert_numeric_to_str(block_info) transactions = block_info.pop(‘transactions’) db["block_info"].insert_one(block_info) but When …

Total answers: 1

Questions regarding transactions on psycopg2

Questions regarding transactions on psycopg2 Question: If I have a transaction that saves data in the database, but this transaction is part of another transaction that needs the id(fk) of that data to create a new data, but an error occurs at that moment, all transactions are rolled back or just the last transaction? Asked …

Total answers: 1

What is the use case for Django's on_commit?

What is the use case for Django's on_commit? Question: Reading this documentation https://docs.djangoproject.com/en/4.0/topics/db/transactions/#django.db.transaction.on_commit This is the use case for on_commit with transaction.atomic(): # Outer atomic, start a new transaction transaction.on_commit(foo) # Do things… with transaction.atomic(): # Inner atomic block, create a savepoint transaction.on_commit(bar) # Do more things… # foo() and then bar() will be called …

Total answers: 2

How to create new database connection in django

How to create new database connection in django Question: I need to create a new database connection(session) to avoid an unexpected commit from a MySql procedure in my django transaction. How to set up it in django? I have tried to duplicate the database configuration in setting file. It worked for me but it seems …

Total answers: 2

Django decorator @transaction.non_atomic_requests not working in a ViewSet method

Django decorator @transaction.non_atomic_requests not working in a ViewSet method Question: I recently ran into the need to disable transaction requests in one of my views, in order to be able to call db.connection.close() and connect() during requests in an effort to improve performance. I have a DRF ViewSet, and used the following very simple view …

Total answers: 2

Default isolation level for transaction (@atomic) with Django and PostgreSQL

Default isolation level for transaction (@atomic) with Django and PostgreSQL Question: I was wondering what’s the default isolation level when using Django with PostgreSQL. Serializable Isolation? (https://www.postgresql.org/docs/9.1/static/transaction-iso.html#XACT-SERIALIZABLE) There is a discussion about MySQL (Django transaction isolation level in mysql & postgresql) but despite its name is doesn’t seem to discuss PostgreSQL Thanks! Asked By: Alex …

Total answers: 3

How to create multiple complex sqlite transactions with an expected out using apsw?

How to create multiple complex sqlite transactions with an expected out using apsw? Question: I want to execute several complex statements in a transaction with a select statement at the end which I use for further processing. Doing so once works fine but as soon as I execute the same statement again it causes the …

Total answers: 1

Django – Rollback save with transaction atomic

Django – Rollback save with transaction atomic Question: I am trying to create a view where I save an object but I’d like to undo that save if some exception is raised. This is what I tried: class MyView(View): @transaction.atomic def post(self, request, *args, **kwargs): try: some_object = SomeModel(…) some_object.save() if something: raise exception.NotAcceptable() # …

Total answers: 3

How to set "REPEATABLE READ" for a transaction In Django?

How to set "REPEATABLE READ" for a transaction In Django? Question: I have a function, that does multiple queries on the same dataset and I want to ensure all the queries would see exactly the same data. In terms of SQL, this means REPEATABLE READ isolation level for the databases that support it. I don’t …

Total answers: 3

What is the simplest way to retry a Django view upon an exception being raised?

What is the simplest way to retry a Django view upon an exception being raised? Question: I want to rerun a Django view function if a certain exception is raised (in my case a serialization error in the underlying database). I want it to run with exactly the same parameters, including the same request object …

Total answers: 2