Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQL Engine Exception about a connection name not existing in registry

I get the following exception while trying to connect to a Cassandra DB using a Python Cassandra-Driver client running on Windows 2012 Server R2 - 64 bit. I could get this working on my personal laptop but not a machine that is hosted on Azure. I am sure I am missing some dependencies but just unsure about what they are.

File "C:\Python\Python35-32\lib\site-packages\cassandra\cqlengine\connection.py", line 190, in get_connection raise CQLEngineException("Connection name '{0}' doesn't exist in the registry.".format(name)) Cassandra.cqlengine.CQLEngineException: Connection name '' doesnt exist in the registry.

like image 587
Praneesh Avatar asked Sep 27 '16 08:09

Praneesh


2 Answers

This is a known issue and will be fixed in the next release (3.8.0): https://datastax-oss.atlassian.net/browse/PYTHON-649

As a workaround, you can see if it's possible to setup the connection before any UDT model definition or downgrade to 3.6.

like image 161
Alan Boudreault Avatar answered Sep 29 '22 03:09

Alan Boudreault


I also run into this (cassandra-driver 3.13), since I had to decouple cassandra shared models from some flask apps and other simple components for batch processing. What I eventually found it's working is in the snippet below (important bits are register_connection and set_default_connection functions):

import os

from cassandra.cluster import Cluster
from cassandra.cqlengine.connection import register_connection, set_default_connection
from flask_cqlalchemy import CQLAlchemy

cqldb = CQLAlchemy()
_keyspace = os.environ.get('CASSANDRA_KEYSPACE', 'persistent')
_hosts = [os.environ.get('CASSANDRA_HOST', 'cassandra')]
_port = os.environ.get('CASSANDRA_PORT', 9042)


def cassandra_session_factory():
    cluster = Cluster(_hosts, port=_port)
    session = cluster.connect()
    session.row_factory = dict_factory
    session.execute("USE {}".format(_keyspace))
    return session


_session = cassandra_session_factory()
register_connection(str(_session), session=_session)
set_default_connection(str(_session))


class MyModel(cqldb.Model):
    """
    Object representing the `model` column family in Cassandra
    """
    __keyspace__ = _keyspace

    session = _session
    session.default_fetch_size = 1000

    myfield = cqldb.columns.Text(primary_key=True, required=True)
like image 34
BangTheBank Avatar answered Sep 29 '22 05:09

BangTheBank