cqlengine collections with missing/null values set to empty

14 views
Skip to first unread message

Michael

unread,
Oct 28, 2016, 4:28:58 PM10/28/16
to DataStax Python Driver for Apache Cassandra User Mailing List
Hello,

I'm using a model with collections, e.g. a list

class mytable(Model):
    key = columns.Text(primary_key=True)
    coll = columns.List(columns.Integer, default=None)

When I instantiate an object, or query for such objects, coll is always initialized to [] even if these values are absent in mytable:

In [1]: mytable(key='123', coll=None)

Out[1]: mytable(key='123', coll=[])


In [2]: mytable(key='123')

Out[2]: mytable(key='123', coll=[])


I've also tried without the default argument, or setting it to types.NoneType (fails with stdlib error cannot create 'NoneType' instances).

For a query it's the same. I've logged mytable.__init__ and it gets the coll=None kwarg same way.

The contents of the table are:

cqlsh:myspace> select * from mytable;


 key                                  | coll

--------------------------------------+------

 2381fcdb-5634-4fd8-a94f-b632d0b57dac | null


I wonder if this is the intended behavior? Shouldn't a non-existent value and an empty collection be treated different?
I've checked this in driver version 3.7.1 and 2.7.2

For my application, I could live with an empty list but there are currently API tests that assert certain keys as None that I would need to change. This means also potentially affecting application logic too albeit unlikely.

Thanks,
Michael

Alan Boudreault

unread,
Oct 31, 2016, 11:17:38 AM10/31/16
to python-dr...@lists.datastax.com
Hello Michael,

Ideally, this should be treated differently. This is a little misconception since the first release of cqlengine. Unfortunately, modifying this behavior will potentially affect many users. It would be preferable to find a workaround for your API tests at the application level.

Regards,
Alan

--
You received this message because you are subscribed to the Google Groups "DataStax Python Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-user+unsub...@lists.datastax.com.



--

Alan Boudreault
Software Engineer (Drivers) | alan.bo...@datastax.com


Reply all
Reply to author
Forward
0 new messages