Inserting an empty value in a map column

51 views
Skip to first unread message

Daniel Santos

unread,
Jul 11, 2019, 5:17:35 PM7/11/19
to python-dr...@lists.datastax.com
Hello,

I have the following model in a django app :

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model

class Event(Model):

sessionid = columns.UUID(primary_key=True, db_field="sessionid")
correlationid = columns.UUID(db_field="correlationid")
datetime = columns.DateTime(db_field="datetime")
typeAttr = columns.Text(db_field="type")
action = columns.Text(db_field="action")
panel = columns.Text(db_field="panel")
objectAttr = columns.Text(db_field="object")
method = columns.Text(db_field="method")
error = columns.Text(db_field="error")
url = columns.Text(db_field="url")
isrequest = columns.Boolean(db_field="isrequest")
imagekey = columns.UUID(db_field="imagekey")
properties = columns.Map(key_type=columns.Text, value_type=columns.Text)

__table_name__ = 'events'

Then I have the following code that creates an Event and saves it to cassandra :

usageEvent = Event()
usageEvent.correlationid = uuid1()
usageEvent.sessionid = UUID(event['correlationid'])
usageEvent.datetime = datetime.strptime(event['datetimestr'], '%d/%m/%Y, %H:%M:%S')
usageEvent.typeAttr = event['eventtype']
usageEvent.action = event['context']
usageEvent.properties = event.get("properties") if event.get("properties") else {}
usageEvent.save()

When the above code runs I get the following traceback :

DEBUG [Connection: DEFAULT_CONNECTION] INSERT INTO xekmypic.events ("sessionid", "correlationid", "datetime", "type", "action") VALUES (%(0)s, %(1)s, %(2)s, %(3)s, %(4)s)
DEBUG [Connection: DEFAULT_CONNECTION] DELETE "properties" FROM xekmypic.events WHERE "sessionid" = %(0)s
Traceback (most recent call last):
File "/Users/dlsa/code/xekmypic/clientapi/authenticator.py", line 102, in wrapper
return function(request, customerObj)
File "/Users/dlsa/code/xekmypic/clientapi/upload.py", line 300, in receiveEvents
usageEvent.save()
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/models.py", line 739, in save
if_exists=self._if_exists).save()
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/query.py", line 1489, in save
self._delete_null_columns()
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/query.py", line 1395, in _delete_null_columns
self._execute(ds)
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/query.py", line 1360, in _execute
results = _execute_statement(self.model, statement, self._consistency, self._timeout, connection=connection)
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/query.py", line 1515, in _execute_statement
return conn.execute(s, params, timeout=timeout, connection=connection)
File "/Users/dlsa/code/virtualenvs/xekmypicpython3.4/lib/python3.4/site-packages/cassandra/cqlengine/connection.py", line 340, in execute
result = conn.session.execute(query, params, timeout=timeout)
File "cassandra/cluster.py", line 2134, in cassandra.cluster.Session.execute (cassandra/cluster.c:37114)
File "cassandra/cluster.py", line 4026, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:77264)
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Range deletions are not supported for specific columns”

So it is issuing a delete for the properties map. Why ? How can I do this ?

Many thanks,
Regards

Alan Boudreault

unread,
Jul 11, 2019, 7:36:27 PM7/11/19
to python-dr...@lists.datastax.com
Hi Daniel,

About the DELETE you see in the logs, it's expected. Since the driver still supports early versions of Cassandra that don't have the CQL literal null, we cannot accomplish this operation in a single query. You can read more about this here: https://issues.apache.org/jira/browse/CASSANDRA-3783 and https://datastax-oss.atlassian.net/browse/PYTHON-506.

However, I'm not sure why you are getting this error with your "events" table since it doesn't seem to have any clustering keys. I will dig a bit more about that. In the meantime, you can probably do this workaround:
usageEvent = Event()
usageEvent.correlationid = uuid1()
usageEvent.sessionid = UUID(event['correlationid'])
usageEvent.datetime = datetime.strptime(event['datetimestr'], '%d/%m/%Y, %H:%M:%S')
usageEvent.typeAttr = event['eventtype']
usageEvent.action = event['context']
# If you don't set the properties field explicitly, cqlengine wont include it in its insert query and no delete query should be sent.
if event.get("properties"):
    usageEvent.properties = event.get("properties")
usageEvent.save()

Also, what is the version of your cassandra server and the cassandra-driver?

Thanks,
Alan

--
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-u...@lists.datastax.com.



--

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


Daniel Santos

unread,
Jul 12, 2019, 5:08:50 PM7/12/19
to python-dr...@lists.datastax.com
Hello,

Thank you for the quick reply. My version of the driver is 
cassandra-driver        3.13.0

The cassandra database version is dsc-cassandra-3.0.9

Thankyou
Regards

Alexandre Paulo dos Santos

unread,
Jul 29, 2024, 7:42:39 PM7/29/24
to DataStax Python Driver for Apache Cassandra User Mailing List, Daniel Santos
Hi! A little late but, have you guys any update about that issue?
I'm getting the same problem in version 3.25

Thank you
Reply all
Reply to author
Forward
0 new messages