Added a thrown exception when a transaction fails to be applied
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -45,3 +45,6 @@ docs/_build
|
||||
|
||||
#iPython
|
||||
*.ipynb
|
||||
|
||||
cqlengine/tests/*
|
||||
cqlengine/tests*
|
||||
@@ -2,5 +2,6 @@
|
||||
class CQLEngineException(Exception): pass
|
||||
class ModelException(CQLEngineException): pass
|
||||
class ValidationError(CQLEngineException): pass
|
||||
class TransactionException(CQLEngineException): pass
|
||||
|
||||
class UndefinedKeyspaceException(CQLEngineException): pass
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user