r4fek / django-cassandra-engine

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

fix python manage.py test cannot use correct db options #119

Closed Ningchen-Wang closed 3 years ago

Ningchen-Wang commented 6 years ago

I found that in this function, the pop operation on settings dict may change the settings in other objects. As a result, 'lazy_connect', 'retry_connect' and 'consistency' options will become invalid after the first connection establishing. During the Django testing, Cassandra connection settings are ignored makes me continually encounter ConsistencyLevel issues. Here are some logs during a Django test

{'ENGINE': 'django_cassandra_engine', 'NAME': '***', 'TEST': {'NAME': '***', 'CHARSET': None, 'COLLATION': None, 'MIRROR': None}, 'HOST': '***', 'OPTIONS': {'replication': {'strategy_class': 'SimpleStrategy', 'replication_factor': 3}, 'connection': {'consistency': 1}}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'USER': '', 'PASSWORD': '', 'PORT': ''}
{'ENGINE': 'django_cassandra_engine', 'NAME': '***', 'TEST': {'NAME': '***', 'CHARSET': None, 'COLLATION': None, 'MIRROR': None}, 'HOST': '***', 'OPTIONS': {'replication': {'strategy_class': 'SimpleStrategy', 'replication_factor': 3}, 'connection': {}}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'USER': '', 'PASSWORD': '', 'PORT': ''}
Creating test database for alias 'default'...
Creating test database for alias 'cassandra'...
{'ENGINE': 'django_cassandra_engine', 'NAME': '***', 'TEST': {'NAME': '***', 'CHARSET': None, 'COLLATION': None, 'MIRROR': None}, 'HOST': '***', 'OPTIONS': {'replication': {'strategy_class': 'SimpleStrategy'}, 'connection': {}}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'USER': '', 'PASSWORD': '', 'PORT': ''}
{'ENGINE': 'django_cassandra_engine', 'NAME': '***', 'TEST': {'NAME': '***', 'CHARSET': None, 'COLLATION': None, 'MIRROR': None}, 'HOST': '***', 'OPTIONS': {'replication': {'strategy_class': 'SimpleStrategy'}, 'connection': {}}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'USER': '', 'PASSWORD': '', 'PORT': ''}

I am not sure whether this is by design since 'replication_factor' is also popped at somewhere else, but I think modifying external objects through this is confusing.