Added a thrown exception when a transaction fails to be applied

This commit is contained in:
timmartin19
2014-10-08 17:11:19 -04:00
parent 44a5181009
commit f9874c7787
3 changed files with 11 additions and 1 deletions

3
.gitignore vendored
View File

@@ -45,3 +45,6 @@ docs/_build
#iPython
*.ipynb
cqlengine/tests/*
cqlengine/tests*

View File

@@ -2,5 +2,6 @@
class CQLEngineException(Exception): pass
class ModelException(CQLEngineException): pass
class ValidationError(CQLEngineException): pass
class TransactionException(CQLEngineException): pass
class UndefinedKeyspaceException(CQLEngineException): pass

View File

@@ -6,7 +6,7 @@ from cqlengine.columns import Counter, List, Set
from cqlengine.connection import execute
from cqlengine.exceptions import CQLEngineException, ValidationError
from cqlengine.exceptions import CQLEngineException, ValidationError, TransactionException
from cqlengine.functions import Token, BaseQueryFunction, QueryValue, UnicodeMixin
#CQL 3 reference:
@@ -836,6 +836,12 @@ class DMLQuery(object):
return self._batch.add_query(q)
else:
tmp = execute(q, consistency_level=self._consistency)
if tmp and tmp[0].get('[applied]', True) is False:
tmp[0].pop('[applied]')
expected = ', '.join('{0}={1}'.format(t.field, t.value) for t in q.transactions)
actual = ', '.join('{0}={1}'.format(f, v) for f, v in tmp[0].items())
message = 'Transaction statement failed: Expected: {0} Actual: {1}'.format(expected, actual)
raise TransactionException(message)
return tmp
def batch(self, batch_obj):