A
A
andrewshkovskii2012-10-30 16:11:26
PostgreSQL
andrewshkovskii, 2012-10-30 16:11:26

Nested transactions / partial persistence of django models?

There is a method that performs certain actions and logs whether these actions were completed, how and by whom.
There is a problem if an error occurs during the execution of actions - all created model instances, except for logs, must be deleted - i.e. do rollback. But along with the rollback, the logs will also be deleted. How to be in this case?
Is the entire chain of changed models saved in savepoints? Is it possible to nest transactions?
I tried through enter_transaction_management /leave_transaction_management - an exception occurred at runtime, first TransactionManagementError("This code isn't under transaction management"), but it could not be caught / suppressed, and I first checked that is_managed ...
Python 2.7.3, Django 1.4.2, postgresql 9.1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FloppyFormator, 2012-10-30
@FloppyFormator

If these are user action logs, then I would suggest checking for a possible error and restoring the previous state explicitly, i.e. not relying on database tools. If these are system logs, then it hardly makes sense to keep them in the database: for example, an error connecting to the database will never get into these logs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question