Django Transaction Errors

I have a cronjob that processes emails and saves them in the system. It has been working well for over a year, but now it has suddenly started to give out these strange transaction errors from time to time.

2010-09-02-01:45:11 ERROR Exception occured during mail processing
Traceback (most recent call last):
 File "/var/www/example.com/project/scripts/cronjobs.py", line 453, in process_msg
   source, email, 'i' if rejection_reason else 'v', rejection_reason)
 File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 267, in _commit_manually
   leave_transaction_management()
 File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 77, in leave_transaction_management
   raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

This happens for no reason, and there is no other context information available to me. Here is the structure of my process_msg function:

@commit_manually
def save_email( u,l, d, t, s, e, status, reason):
    try:
        # ... bla bla bla ... 
        commit()
    exception, e:
        rollback()
        raise e

def process_msg(m):
    try:
        #....
        save_email(u, l, d, t
            source, email, 'i' if rejection_reason else 'v', rejection_reason)
        #....
     except Exception, e:
        logger.error('Error while processing email', exc_info=True )
        return None
    else:
        return True

How do I research this problem?

+3
source share
1 answer

There seems to be an error before logging in save_email(). Without a directive commit()or rollback()in process_msg(), a TransactionError occurs.

You can try to circle the error using the debugger:

def process_msg(m):
    try:
        import pdb                    # import python debugger
        pdb.set_trace()               # begin debugging
        #....
        save_email(u, l, d, t,
        […]

- Python.

0

Source: https://habr.com/ru/post/1763072/


All Articles