Cassandra: "Model keyspace not set" and "Connection name doesn't exist in the registry" Errors

44 Views Asked by At

I recently upgraded to Django 4.2 and am facing issues with Cassandra integration. Initially, I encountered the following error when attempting to generate queries:

cassandra.cqlengine.CQLEngineException: Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.

This error was thrown despite specifying the model keyspace in settings.py. As an attempted fix, I explicitly set the keyspace in my models like so:

__keyspace__ = "my_keyspace"

However, this led to a new set of errors related to connection names not existing in the registry:

Connection name '<object object at 0x7f4fb00d67a0>' doesn't exist in the registry.

This issue persists across multiple models and queries. Here are some relevant details about my setup:

  • Python 3.10
  • django-cassandra-engine 1.7.0
  • Running inside Docker; connectivity to Cassandra from within Docker has been verified

Here's a full error.

sessions, disconnected = fetch_sessions_list(ux_vms)
  File "/code/wtools2/apps/analytics/views.py", line 1652, in fetch_sessions_list
    metrics_session.extend(list(sessions_db))
  File "/usr/local/lib/python3.10/site-packages/cassandra/cqlengine/query.py", line 437, in __len__
    self._execute_query()
  File "/usr/local/lib/python3.10/site-packages/cassandra/cqlengine/query.py", line 472, in _execute_query
    self._result_generator = (i for i in self._execute(self._select_query()))
  File "/usr/local/lib/python3.10/site-packages/cassandra/cqlengine/query.py", line 456, in _select_query
    self.column_family_name,
  File "/usr/local/lib/python3.10/site-packages/cassandra/cqlengine/query.py", line 397, in column_family_name
    return self.model.column_family_name()
  File "/usr/local/lib/python3.10/site-packages/cassandra/cqlengine/models.py", line 559, in column_family_name
    raise CQLEngineException("Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.")

cassandra.cqlengine.CQLEngineException: Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.
raise CQLEngineException("Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.")
cassandra.cqlengine.CQLEngineException: Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.

Has anyone faced similar issues or have insights on resolving these errors in a Django 4.2 environment with Cassandra? Any help or guidance would be greatly appreciated.

0

There are 0 best solutions below