7

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.

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Praneesh
  • 363
  • 3
  • 11
  • 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. – Praneesh Sep 27 '16 at 11:59

2 Answers2

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)
BangTheBank
  • 809
  • 3
  • 11
  • 26
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.

Alan Boudreault
  • 329
  • 1
  • 5
  • 2
    This seems to still be an issue as of 3.12.0 Did it get sorted out by any chance? (granted on line 241) – Kelvin Jan 28 '18 at 18:56