Ignore empty batches instead of sending invalid CQL to Cassandra.

This commit is contained in:
Kai Lautaportti
2013-03-22 09:52:18 +02:00
parent e10237e855
commit cad39537ef
2 changed files with 14 additions and 4 deletions

View File

@@ -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)

View File

@@ -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