Bug with Static Columns & Null Values

65 views
Skip to first unread message

Aaron Benz

unread,
Jul 16, 2016, 10:08:25 PM7/16/16
to DataStax Python Driver for Apache Cassandra User Mailing List
I haven't been able to pinpoint this bug, but it looks like there is a delete statement occurring that C* doesn't like. This query used to work (for sure in V2.6.0), but not in 3.5 (or head on github). 

Repeatable steps and error:


#creating table
from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect()
session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};")
session.execute("CREATE TABLE IF NOT EXISTS test.tester ( example_static1 int static, example_static2 int static, example_id int, example_clust int, PRIMARY KEY (example_id, example_clust) );")


#######################
#run to generate bug below
#########################
import uuid
from cassandra.cqlengine import columns
from cassandra.cqlengine import connection
from datetime import datetime
from cassandra.cqlengine.management import sync_table
from cassandra.cqlengine.models import Model

#first, define a model
class ExampleModel(Model):
    __keyspace__ = "test"
    __table_name__ = "tester"
    example_id      = columns.Integer(partition_key=True, primary_key=True, default=uuid.uuid4)
    example_static1    = columns.Integer(static=True)
    example_static2    = columns.Integer(static=True)
    example_clust      = columns.Integer(primary_key=True)


connection.setup(['127.0.0.1'], "cqlengine", protocol_version=3)

ExampleModel.create(example_id=5, example_clust=5, example_static2=None)

#OR#
ExampleModel.create(example_id=5, example_clust=5, example_static2=1)
em = ExampleModel.filter(example_id=5).first()
print em.example_static2 #output was 1
em.update(example_static2=None)


####Traceback
InvalidRequest                            Traceback (most recent call last)
<ipython-input-78-0edeb9434fd9> in <module>()
----> 1 ExampleModel.create(example_id=5, example_clust=5, example_static2=None)

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/models.pyc in create(cls, **kwargs)
    622         if extra_columns:
    623             raise ValidationError("Incorrect columns passed: {0}".format(extra_columns))
--> 624         return cls.objects.create(**kwargs)
    625 
    626     @classmethod

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/query.py in create(self, **kwargs)
    839             .if_not_exists(self._if_not_exists) \
    840             .timestamp(self._timestamp) \
--> 841             .if_exists(self._if_exists) \
    842             .save()
    843 

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/models.pyc in save(self)
    688                           conditional=self._conditional,
    689                           timeout=self._timeout,
--> 690                           if_exists=self._if_exists).save()
    691 
    692         self._set_persisted()

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/query.py in save(self)
   1260         # delete any nulled columns
   1261         if not static_save_only:
-> 1262             self._delete_null_columns()
   1263 
   1264     def delete(self):

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/query.py in _delete_null_columns(self, conditionals)
   1170             for name, col in self.model._primary_keys.items():
   1171                 ds.add_where(col, EqualsOperator(), getattr(self.instance, name))
-> 1172             self._execute(ds)
   1173 
   1174     def update(self):

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/query.py in _execute(self, statement)
   1139             return self._batch.add_query(statement)
   1140         else:
-> 1141             results = _execute_statement(self.model, statement, self._consistency, self._timeout)
   1142             if self._if_not_exists or self._if_exists or self._conditional:
   1143                 check_applied(results)

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/query.py in _execute_statement(model, statement, consistency_level, timeout)
   1285             s.routing_key = parts
   1286             s.keyspace = model._get_keyspace()
-> 1287     return connection.execute(s, params, timeout=timeout)
   1288 # Contact GitHub API Training Shop Blog About

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cqlengine/connection.pyc in execute(query, params, consistency_level, timeout)
    168     log.debug(query.query_string)
    169 
--> 170     result = session.execute(query, params, timeout=timeout)
    171 
    172     return result

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.Session.execute (cassandra/cluster.c:33653)()

/Users/aaronbenz/myProgs/environments/zyncup-cassandra-api/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:69380)()

InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid restrictions on clustering columns since the DELETE statement modifies only static columns"

Adam Holmberg

unread,
Jul 18, 2016, 3:16:21 PM7/18/16
to python-dr...@lists.datastax.com
Aaron,

Thanks for bringing this up. I can confirm this is a deficiency. However, I see the same behavior going all the way back to the first version integrating cqlengine (I tried 2.6.0 and 2.5.0). Can you try again and show it working in 2.6.0?

In any event, I've created PYTHON-608 to take care of this.

Regards,
Adam Holmberg

--
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-u...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages