Cannot share session between cqlengine and basic CQL with user types

Description

Querying a model instance with a UserType column, while sharing the same session with an application that registers a user type class, results in wrong type of UDT value and error on modification/save of that model instance.

Steps to reproduce:

  • create a session = Cluster(nodes, kwargs).connect(keyspace).

  • registers a class for a UDT with session.cluster.register_user_type(keyspace, udt_name, app_udt_class)

  • initialize cqlengine by calling connection.set_session(session)

  • define a UserType

  • define a Model using the UDT as a column (or as value of a collection column)

  • call x = model.get(key=value)

  • print type(x.udt_column)

  • modify UDT column

  • call x.save()

Actual result:

  • type of UDT column is app_udt_class

  • cannot update UDT column value

  • error on x.save()

Expected result:

  • type of UDT columns is cqlengine UserType subclass

  • can modify UDT value

  • can save

Note: Using a separate session for cqlengine and the application that uses basic CQL queries solves this issue at the cost of having 2 open connections to Cassandra per app process.

Environment

None

Pull Requests

None

Activity

Show:
Michael Meisinger
December 2, 2016, 11:17 AM
Edited

The attached script cqlengine_udt.py shows a sequence of steps to reproduce the situation. The output is:

cluster._user_types initially: defaultdict(<type 'dict'>, {})
UDT class using cqlengine initially: <class '_main_.myudt'>
cluster.user_types after UserType def: defaultdict(<type 'dict'>, {'ks': {'myudt': <class 'main_.myudt'>}})
cluster.user_types after register_user_type: defaultdict(<type 'dict'>, {'ks': {'myudt': <class 'main_.UDTWrapper'>}})
UDT class using CQL query: <class '_main_.UDTWrapper'>
UDT class using cqlengine after UDT registration: <class '_main_.UDTWrapper'>

Expected would be as last line:

UDT class using cqlengine after UDT registration: <class '_main_.myudt'>

Assignee

Unassigned

Reporter

Michael Meisinger

Fix versions

None

Reproduced in

None

PM Priority

None

External issue ID

None

Doc Impact

None

Reviewer

None

Size

None

Pull Request

None

Sprint

Py P-NEXT

Affects versions

Priority

Minor