Issue with List of UserDefinedType

37 views
Skip to first unread message

Dang Pham

unread,
Jul 7, 2015, 9:02:55 PM7/7/15
to python-dr...@lists.datastax.com
I have a defined class as follow:
class track(UserType):
    title = Text()
    artist = Text()
    album = Text()
    uri = Text()
    length = Integer()
    played = Integer()
    start_time = DateTime()
And a model defined:
class Sessions(Model):
    username = Text(primary_key=True)
    sessions = DateTime(primary_key=True)
    tracks = List(UserDefinedType(track))

Whenever I try to create a sessions instance 
Sessions.create(hh='abc', sessions=datetime.datetime.now(), tracks=[track(title="Example",artist='hello', album='sdfads',length=123,start_time=datetime.datetime.now())])


I get this error
cassandra.protocol.SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:219 mismatched input ':' expecting ')' (...23.279881, 'title': Example, 'uri'[:] None...)">

I'm not sure what's wrong with the code as I tried adding a record manually through cqlsh and it worked fine. Am I using the List type correctly?


Adam Holmberg

unread,
Jul 8, 2015, 1:17:50 PM7/8/15
to python-dr...@lists.datastax.com
I do not get the same error when attempting this here. Can you specify your client and server versions?

One thing I did notice is that you're creating with a keyword parameter 'hh', which is not a field in the Session model. This would result in cassandra.cqlengine.ValidationError: Incorrect columns passed: set(['hh']). Changing 'hh' -> 'username' made the creation work as expected in my test.

Adam Holmberg

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

Dang Pham

unread,
Jul 8, 2015, 2:15:19 PM7/8/15
to python-dr...@lists.datastax.com
Yes I fixed the hh -> username issue. I'm still getting the error. I'm using Cassandra 2.1.7 and the python driver 2.5.1.

Is there a way to check the query that the object.create() method is calling?

Adam Holmberg

unread,
Jul 8, 2015, 2:22:40 PM7/8/15
to python-dr...@lists.datastax.com
The pre-substitution query is debug-logged in cassandra.cqlengine.connection:
https://github.com/datastax/python-driver/blob/2.5.1/cassandra/cqlengine/connection.py#L166

To see the interpolated parameters, you would need to sniff the wire or add something printing query_string here:

I'll try again here with your specific versions.

Adam


Dang Pham

unread,
Jul 8, 2015, 6:40:44 PM7/8/15
to python-dr...@lists.datastax.com
After fiddling around, I think the issue is the that the track object is not getting encoded into a cql string correctly. It just returns the str of the track object.

This is the query string I'm getting:

'INSERT INTO trackplay.sessions ("username", "sessions", "tracks") VALUES (\'testuser\', 1436369702735, [{\'album\': test album, \'artist\': None, \'start_time\': 2360-02-29 14:45:12, \'title\': Example, \'uri\': www.hello.com, \'sec\': 123, \'sa\': 123}])'

However the correct query should be:

'INSERT INTO trackplay.sessions ("username", "sessions", "tracks") VALUES (testuser, 1436357303671, [{album: \'test album\', artist: null, start_time: \'2015-07-08 12:08:23.671151\', title: \'Example\', uri: \'www.hello.com\', sec: 123, sa: 123}])'

Correct me if I'm wrong but I think the issue is in the encoding of UserDefinedType which is being treated as a generic object.

Adam Holmberg

unread,
Jul 8, 2015, 6:44:56 PM7/8/15
to python-dr...@lists.datastax.com
You are correct. I believe this is https://datastax-oss.atlassian.net/browse/PYTHON-311

It's fixed in 2.6.0c1. You can install that pre-release version, or wait for the GA release, which will coincide with Cassandra 2.2 GA.

Sorry for the inconvenience.

Adam

Reply all
Reply to author
Forward
0 new messages