Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Proper transactions #74

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ envlist =
pypy3-twisted15

[testenv]
passenv = DBTYPE
sitepackages = True
deps =
coverage
twisted>=15.0, <16.0
Expand Down
11 changes: 5 additions & 6 deletions twistar/dbconfig/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from twistar.registry import Registry
from twistar.exceptions import ImaginaryTableError, CannotRefreshError
from twistar.utils import joinWheres
from twistar.transaction import TransactionGuard


class InteractionBase(object):
Expand All @@ -25,7 +26,7 @@ class InteractionBase(object):


def __init__(self):
self.txn = None
self.txnGuard = TransactionGuard()


def logEncode(self, s, encoding='utf-8'):
Expand Down Expand Up @@ -156,7 +157,6 @@ def _doselect(self, txn, q, args, tablename, one=False, cacheable=True):
results.append(vals)
return results


def insertArgsToString(self, vals):
"""
Convert C{{'name': value}} to an insert "values" string like C{"(%s,%s,%s)"}.
Expand Down Expand Up @@ -327,8 +327,8 @@ def getSchema(self, tablename, txn=None):


def runInteraction(self, interaction, *args, **kwargs):
if self.txn is not None:
return defer.succeed(interaction(self.txn, *args, **kwargs))
if self.txnGuard.txn is not None:
return defer.succeed(interaction(self.txnGuard.txn, *args, **kwargs))
return Registry.DBPOOL.runInteraction(interaction, *args, **kwargs)


Expand All @@ -345,8 +345,7 @@ def _doinsert(txn):
if len(cols) == 0:
raise ImaginaryTableError("Table %s does not exist." % tablename)
vals = obj.toHash(cols, includeBlank=self.__class__.includeBlankInInsert, exclude=['id'])
self.insert(tablename, vals, txn)
obj.id = self.getLastInsertID(txn)
obj.id = self.insert(tablename, vals, txn)
return obj

return self.runInteraction(_doinsert)
Expand Down
3 changes: 2 additions & 1 deletion twistar/dbobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from twistar.registry import Registry
from twistar.relationships import Relationship
from twistar.exceptions import InvalidRelationshipError, DBObjectSaveError, ReferenceNotSavedError
from twistar.utils import createInstances, deferredDict, dictToWhere, transaction
from twistar.utils import createInstances, deferredDict, dictToWhere
from twistar.transaction import transaction
from twistar.validation import Validator, Errors

from BermiInflector.Inflector import Inflector
Expand Down
Loading