Ticket #11900: 11900_patch_and_tests.diff

File 11900_patch_and_tests.diff, 1.9 KB (added by Gabriel Hurley, 15 years ago)

Updates patch to work w/ MultiDB and adds tests

  • django/db/transaction.py

     
    304304                    raise
    305305                else:
    306306                    if is_dirty(using=db):
    307                         commit(using=db)
     307                        try:
     308                            commit(using=db)
     309                        except:
     310                            rollback(using=db)
     311                            raise
    308312                return res
    309313            finally:
    310314                leave_transaction_management(using=db)
  • tests/modeltests/transactions/models.py

     
    130130TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
    131131
    132132"""
     133
     134# Test for bug 11900, better error handling for commits during commit_on_success blocks.
     135# The bug has only been verified to occur using the psycopg2 backend, though the fix is generally a good idea.
     136pgsql_backends = ('django.db.backends.postgresql_psycopg2', 'postgresql_psycopg2',)
     137if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] in pgsql_backends:
     138    __test__['API_TESTS'] += """
     139>>> def execute_bad_sql():
     140...     cursor = connection.cursor()
     141...     cursor.execute('INSERT INTO auth_user_groups (user_id, group_id) VALUES (1000000, 1000000);')
     142...     transaction.set_dirty()
     143...
     144>>> execute_bad_sql = transaction.commit_on_success(execute_bad_sql)
     145>>> execute_bad_sql()
     146Traceback (most recent call last):
     147    ...
     148IntegrityError: insert or update on table "auth_user_groups" violates foreign key constraint "auth_user_groups_user_id_fkey"
     149DETAIL:  Key (user_id)=(1000000) is not present in table "auth_user".
     150"""
     151 No newline at end of file
Back to Top