How an upgrade to Cassandra 4.0.5 broke my Python

I’ve got a bunch of Python 2.7 code hooked up to Cassandra storing there blobs. Cassandra had no problem with returning a bytes or a string. Anyway.

Here I switch to Cassandra 4

Suddenly the blobs I expected to be returned just as I put them, Cassandra responded with either a pronounceable blob or a structure in form of 0xABCD. In order to deal with that I had to write the following code:

def dehexify(x):
    if x.startswith('0x'):
        if len(x) == 2:
            return x
            return x[2:].decode('hex')
        except TypeError:
            # odd-length string or a binary blob at the very least
            return x
    return x

And the result of this function can be safely passed to struct.unpack.

Latest update: the if len(x) == 2 is here to protect you from the 1:65536 cases where Cassandra returns you a binary blob of 0x and fully intends that to be represented as a blob, not as a hex encoding.

I have zero idea what does that depend on, whether Cassandra returns you a blob or an hex-encoded blob, as I have not investigated this phenomenon. I just believe that it exists, and judging from a multitude of stack traces e-mailed to my inbox it does exist.

Lesson learned from today

Switch to Python 3 ASAP!!

For the Love of God, please disable the default setting of write survey in your Cassandra 4.0.5 instance. Some moron apparently made that a default, and if you don’t disable it you will experience miraculous and moon phase dependenent errors in your cluster, such as new nodes replicating the schema but failing to replicate the data at all.

By the way

I’ve been a very active contributor to bring OTEL to Cassandra. It’s written in Java, unfortunately.


The breaking change might have resulted from DataStax’s team changing something in cassandra-driver itself, but the timing seems odd.


By Piotr Maślanka

Programmer, paramedic, entrepreneur, biotechnologist, expert witness. Your favourite renaissance man.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.