cassandracassandra-python-driver

Cassandra issue with delete between filter() and save()


I have an issue where a delete between loading an item and saving it back to cassandra causes columns which were not updated to be deleted.

class TestItem(Model):
    uuid = columns.Integer(primary_key=True)
    data_1 = columns.Text()
    data_2 = columns.Text()

TestItem.create(uuid=1, data_1='data_1', data_2='data_2').save()

item = TestItem.filter(uuid=1).first()
TestItem.objects(uuid=1).delete()
item.data_2 = 'data_2_deleted'

item_b.save()
# stdout:
# TestItem(uuid=1, data_1=u'data_1', data_2='data_2_deleted')

TestItem.filter(uuid=1).first()
# stdout:
# TestItem(uuid=1, data_1=None, data_2=u'data_2_deleted')

I would expect data_1 to still be present.

Is this intended behaviour? Can I change my code somehow that either the item is completely deleted or saved with all values that were queried before.


Solution

  • The issue was that the cassandra driver only writes back the rows which were actually changed.

    In my use case I wanted to write all rows, changed or not, so I used:

    TestItem.create(**dict(item_b)).save()