r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
367 stars 84 forks source link

Collectstatic not working if there is no connection to cassandra database #57

Open rinatio opened 8 years ago

rinatio commented 8 years ago

If we define cassandra in DATABASES and run python api/manage.py collectstatic it fails trying to connect to cluster. Collectstatic doesn't really need cassandra connection and it seems like it does not fail for other DB engines in DATABASES dictionary if there is no connection.

Here's console output:

2016-03-29 11:49:34,936 [WARNING] [none] cassandra.cluster: [control connection] Error connecting to 127.0.0.1:
Traceback (most recent call last):
  File "cassandra/cluster.py", line 2081, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:36992)
    return self._try_connect(host)
  File "cassandra/cluster.py", line 2101, in cassandra.cluster.ControlConnection._try_connect (cassandra/cluster.c:37469)
    connection = self._cluster.connection_factory(host.address, is_control_connection=True)
  File "cassandra/cluster.py", line 789, in cassandra.cluster.Cluster.connection_factory (cassandra/cluster.c:9277)
    return self.connection_class.factory(address, self.connect_timeout, *args, **kwargs)
  File "cassandra/connection.py", line 306, in cassandra.connection.Connection.factory (cassandra/connection.c:5146)
    conn = cls(host, *args, **kwargs)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/cassandra/io/asyncorereactor.py", line 162, in __init__
    self._connect_socket()
  File "cassandra/connection.py", line 340, in cassandra.connection.Connection._connect_socket (cassandra/connection.c:6278)
    raise socket.error(sockerr.errno, "Tried connecting to %s. Last error: %s" % ([a[4] for a in addresses], sockerr.strerror or sockerr))
error: [Errno 61] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused
2016-03-29 11:49:34,938 [ERROR] [none] cassandra.cluster: Control connection failed to connect, shutting down Cluster:
Traceback (most recent call last):
  File "cassandra/cluster.py", line 844, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:11088)
    self.control_connection.connect()
  File "cassandra/cluster.py", line 2055, in cassandra.cluster.ControlConnection.connect (cassandra/cluster.c:36396)
    self._set_new_connection(self._reconnect_internal())
  File "cassandra/cluster.py", line 2090, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:37252)
    raise NoHostAvailable("Unable to connect to any servers", errors)
NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
Traceback (most recent call last):
  File "api/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django_cassandra_engine/models.py", line 5, in <module>
    conn.connect()
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django_cassandra_engine/base/__init__.py", line 94, in connect
    self.connection = CassandraConnection(**settings)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django_cassandra_engine/connection.py", line 58, in __init__
    self.setup()
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/django_cassandra_engine/connection.py", line 70, in setup
    **self.connection_options)
  File "/Users/Rinat/.virtualenvs/maui/lib/python2.7/site-packages/cassandra/cqlengine/connection.py", line 129, in setup
    session = cluster.connect()
  File "cassandra/cluster.py", line 824, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:11386)
  File "cassandra/cluster.py", line 850, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:11208)
  File "cassandra/cluster.py", line 844, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:11088)
  File "cassandra/cluster.py", line 2055, in cassandra.cluster.ControlConnection.connect (cassandra/cluster.c:36396)
  File "cassandra/cluster.py", line 2090, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:37252)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
andreoua commented 5 years ago

It's not clear how the reference linked can help. This seems like a very important issue since it essentially makes any attempt to create a Docker container fail.