CQL Engine Exception about a connection name not existing in registry
Asked Answered
T

2

8

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.

Talmudist answered 27/9, 2016 at 8:52 Comment(1)
This happens with cassandra-driver-3.7. When I downgraded the version to 3.6 and 3.5 things started working. My laptop has 3.5 on it and the new machine had 3.7 version. Still not sure if there is such a big change between the minor updates of driver.Talmudist
A
2

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.

Addle answered 9/11, 2016 at 13:20 Comment(1)
This seems to still be an issue as of 3.12.0 Did it get sorted out by any chance? (granted on line 241)Anneal
N
3

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)
Nazareth answered 25/5, 2018 at 6:55 Comment(0)
A
2

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.

Addle answered 9/11, 2016 at 13:20 Comment(1)
This seems to still be an issue as of 3.12.0 Did it get sorted out by any chance? (granted on line 241)Anneal

© 2022 - 2024 — McMap. All rights reserved.