Ignore empty batches instead of sending invalid CQL to Cassandra.
This commit is contained in:
@@ -169,6 +169,10 @@ class BatchQuery(object):
|
|||||||
self.queries.append((query, params))
|
self.queries.append((query, params))
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
if len(self.queries) == 0:
|
||||||
|
# Empty batch is a no-op
|
||||||
|
return
|
||||||
|
|
||||||
opener = 'BEGIN ' + (self.batch_type + ' ' if self.batch_type else '') + ' BATCH'
|
opener = 'BEGIN ' + (self.batch_type + ' ' if self.batch_type else '') + ' BATCH'
|
||||||
if self.timestamp:
|
if self.timestamp:
|
||||||
epoch = datetime(1970, 1, 1)
|
epoch = datetime(1970, 1, 1)
|
||||||
|
|||||||
@@ -103,3 +103,9 @@ class BatchQueryTests(BaseCassEngTestCase):
|
|||||||
for m in TestMultiKeyModel.all():
|
for m in TestMultiKeyModel.all():
|
||||||
m.delete()
|
m.delete()
|
||||||
|
|
||||||
|
def test_empty_batch(self):
|
||||||
|
b = BatchQuery()
|
||||||
|
b.execute()
|
||||||
|
|
||||||
|
with BatchQuery() as b:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user