Code

MultipleDatabaseSupport: naive-transaction.diff

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

naive first pass at allowing transactions to work

Line 
1diff -ur db/models/base.py /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/base.py
2--- db/models/base.py   2006-06-15 17:46:52.000000000 -0700
3+++ /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/base.py      2006-06-16 16:24:12.000000000 -0700
4@@ -195,7 +195,7 @@
5                      backend.get_pk_default_value()))
6             if self._meta.has_auto_field and not pk_set:
7                 setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
8-        transaction.commit_unless_managed()
9+        transaction.commit_unless_managed(connection=self._meta.connection)
10 
11         # Run any post-save hooks.
12         dispatcher.send(signal=signals.post_save, sender=self.__class__, instance=self)
13@@ -377,7 +377,7 @@
14             backend.quote_name(rel_field.m2m_column_name()),
15             backend.quote_name(rel_field.m2m_reverse_name()))
16         cursor.executemany(sql, [(this_id, i) for i in id_list])
17-        transaction.commit_unless_managed()
18+        transaction.commit_unless_managed(connection=self._meta.connection)
19 
20 ############################################
21 # HELPER FUNCTIONS (CURRIED MODEL METHODS) #
22@@ -398,7 +398,7 @@
23         backend.quote_name(ordered_obj.pk.column))
24     rel_val = getattr(self, ordered_obj.order_with_respect_to.rel.field_name)
25     cursor.executemany(sql, [(i, rel_val, j) for i, j in enumerate(id_list)])
26-    transaction.commit_unless_managed()
27+    transaction.commit_unless_managed(connection=self._meta.connection)
28 
29 def method_get_order(ordered_obj, self):
30     connection_info = ordered_obj.connection_info
31diff -ur db/transaction.py /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/transaction.py
32--- db/transaction.py   2006-06-13 13:11:13.000000000 -0700
33+++ /sw/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/transaction.py      2006-06-16 16:23:28.000000000 -0700
34@@ -111,7 +111,7 @@
35             return state[thread_ident][-1]
36     return settings.TRANSACTIONS_MANAGED
37 
38-def managed(flag=True):
39+def managed(connection=connection,flag=True):
40     """
41     Puts the transaction manager into a manual state: managed transactions have
42     to be committed explicitely by the user. If you switch off transaction
43@@ -128,7 +128,7 @@
44     else:
45         raise TransactionManagementError("This code isn't under transaction management")
46 
47-def commit_unless_managed():
48+def commit_unless_managed(connection=connection):
49     """
50     Commits changes if the system is not in managed transaction mode.
51     """
52@@ -137,7 +137,7 @@
53     else:
54         set_dirty()
55 
56-def rollback_unless_managed():
57+def rollback_unless_managed(connection=connection):
58     """
59     Rolls back changes if the system is not in managed transaction mode.
60     """
61@@ -146,14 +146,14 @@
62     else:
63         set_dirty()
64 
65-def commit():
66+def commit(connection=connection):
67     """
68     Does the commit itself and resets the dirty flag.
69     """
70     connection._commit()
71     set_clean()
72 
73-def rollback():
74+def rollback(connection=connection):
75     """
76     This function does the rollback itself and resets the dirty flag.
77     """