MultipleDatabaseSupport: naive-transaction.diff

File naive-transaction.diff, 3.1 KB (added by Jon Dugan <jdugan@…>, 9 years ago)

naive first pass at allowing transactions to work

  • db/models/base.py

    diff -ur db/models/base.py /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/base.py
    old new  
    195195                     backend.get_pk_default_value()))
    196196            if self._meta.has_auto_field and not pk_set:
    197197                setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
    198         transaction.commit_unless_managed()
     198        transaction.commit_unless_managed(connection=self._meta.connection)
    199199
    200200        # Run any post-save hooks.
    201201        dispatcher.send(signal=signals.post_save, sender=self.__class__, instance=self)
     
    377377            backend.quote_name(rel_field.m2m_column_name()),
    378378            backend.quote_name(rel_field.m2m_reverse_name()))
    379379        cursor.executemany(sql, [(this_id, i) for i in id_list])
    380         transaction.commit_unless_managed()
     380        transaction.commit_unless_managed(connection=self._meta.connection)
    381381
    382382############################################
    383383# HELPER FUNCTIONS (CURRIED MODEL METHODS) #
     
    398398        backend.quote_name(ordered_obj.pk.column))
    399399    rel_val = getattr(self, ordered_obj.order_with_respect_to.rel.field_name)
    400400    cursor.executemany(sql, [(i, rel_val, j) for i, j in enumerate(id_list)])
    401     transaction.commit_unless_managed()
     401    transaction.commit_unless_managed(connection=self._meta.connection)
    402402
    403403def method_get_order(ordered_obj, self):
    404404    connection_info = ordered_obj.connection_info
  • db/transaction.py

    diff -ur db/transaction.py /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/transaction.py
    old new  
    111111            return state[thread_ident][-1]
    112112    return settings.TRANSACTIONS_MANAGED
    113113
    114 def managed(flag=True):
     114def managed(connection=connection,flag=True):
    115115    """
    116116    Puts the transaction manager into a manual state: managed transactions have
    117117    to be committed explicitely by the user. If you switch off transaction
     
    128128    else:
    129129        raise TransactionManagementError("This code isn't under transaction management")
    130130
    131 def commit_unless_managed():
     131def commit_unless_managed(connection=connection):
    132132    """
    133133    Commits changes if the system is not in managed transaction mode.
    134134    """
     
    137137    else:
    138138        set_dirty()
    139139
    140 def rollback_unless_managed():
     140def rollback_unless_managed(connection=connection):
    141141    """
    142142    Rolls back changes if the system is not in managed transaction mode.
    143143    """
     
    146146    else:
    147147        set_dirty()
    148148
    149 def commit():
     149def commit(connection=connection):
    150150    """
    151151    Does the commit itself and resets the dirty flag.
    152152    """
    153153    connection._commit()
    154154    set_clean()
    155155
    156 def rollback():
     156def rollback(connection=connection):
    157157    """
    158158    This function does the rollback itself and resets the dirty flag.
    159159    """
Back to Top