Update Map type columns python models

79 views
Skip to first unread message

Léopold Boudard

unread,
Oct 27, 2016, 3:49:35 AM10/27/16
to DataStax Python Driver for Apache Cassandra User Mailing List
Hello,

I've been encountering some issues using python cassandra models

on latest version 3.7.0

Instanciating a model that have a Map column type and performing update cause column to be overridden even if it hasn't been set:

class Foo(Model):
    id = Integer(primary_key=True)
    mf = Map(Integer, Text)
    dummy = Integer()


foo = Foo(id=1)
foo.dummy = 1
foo.update() # this reset mf column to {}

I've dig into this, and it seems that value manager set as changed any field that isn't equals previous_value=None, while those columns are by default set to empty dict...
Overriding value manager for those columns doesn't solve this issue either as MapColumn have specific rules to be removed in case of update if they're not being updated:

_delete_null_columns
Could you help with this issue?

Thanks!




Alan Boudreault

unread,
Oct 27, 2016, 9:05:41 AM10/27/16
to python-dr...@lists.datastax.com
Léopold,

It looks like this issue is not related to the Map column, but to any column that has a default defined. The ValueManager doesn´t seem to care about that default value.... which lead to the wrong behavior when checking if the value has changed or not. I´ve created an issue about that:


For now, I think the only workaround would be to fetch the model from the DB before the update:

class Foo(Model):
    id = Integer(primary_key=True)
    mf = Map(Integer, Text)
    dummy = Integer()


foo = Foo.objects.get(id=1)
foo.dummy = 1
foo.update() # this reset mf column to {}

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