Attribute Error: at /auth/login/facebook/ Exception Value: operators
Question: Am Using the following configuration with django

  
**cassandra-driver (3.1.0)**  
**Django (1.9.4)**  
**django-cassandra-engine (0.7.0)**  
**django-oauth-toolkit (0.10.0)**  
**django-rest-framework-social-oauth2 (1.0.4)**  
**djangorestframework (3.3.2)**  
**oauthlib (1.0.3)**  
**python-social-auth (0.2.14)**  
  
**Python 2.7.9**  
  
**My site settings.py**  

    
    
    INSTALLED_APPS = [
    'django_cassandra_engine',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'oauth2_provider',
    'userlogin',
    'social.apps.django_app.default',
    'rest_framework_social_oauth2'
    ]
    
    DATABASES = {
        'default': {
            'ENGINE': 'django_cassandra_engine',
            'NAME': 'sample',
            'TEST_NAME' : 'test_sample',
            'HOST': 'localhost'
        }
    }
    
    AUTHENTICATION_BACKENDS = (
            'social.backends.facebook.FacebookOAuth2',
            'social.backends.facebook.FacebookOAuth2',
            'social.backends.google.GoogleOAuth2',
            'social.backends.twitter.TwitterOAuth',
            'django.contrib.auth.backends.ModelBackend',
    )
    
    LOGIN_REDIRECT_URL = '/'
    

**Home.html**  

    
    
    {% extends 'base.html' %} {% block main %}
    <div>
      <h1>Third-party authentication demo</h1>
    
      <p>
        <ul>
          {% if user and not user.is_anonymous %}
          <li>
            <a>Hello {{ user.get_full_name|default:user.username }}!</a>
          </li>
          <li>
            <a href="{% url 'auth:logout' %}?next={{ request.path }}">Logout</a>
          </li>
          {% else %}
          <li>
            <a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}">Login with Facebook</a>
          </li>
          <li>
            <a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login with Google</a>
          </li>
          <li>
            <a href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}">Login with Twitter</a>
          </li>
          {% endif %}
        </ul>
      </p>
    </div>
    {% endblock %}
    

**Views.py**  
from django.shortcuts import render

    
    
    from django.shortcuts import render_to_response
    from django.template.context import RequestContext
    
    def home(request):
            context = RequestContext(request,
                                    {'request': request,
                                    'user': request.user})
            return render_to_response('home.html',
                                    context_instance=context)
    

**URLS.py**  

    
    
    urlpatterns = patterns('',
    url(r'^$', 'userlogin.views.home', name='home'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^auth/', include('rest_framework_social_oauth2.urls')),
    url('', include('social.apps.django_app.urls', namespace='social')),
    url('', include('django.contrib.auth.urls', namespace='auth')),
    )
    

When I access the facebook authetication, i received the following error.

    
    
    Traceback:
    
    File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      235.                 response = middleware_method(request, response)
    
    File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
      50.                         request.session.save()
    
    File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
      80.             return self.create()
    
    File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in create
      49.             self._session_key = self._get_new_session_key()
    
    File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_new_session_key
      155.             if not self.exists(session_key):
    
    File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in exists
      45.         return self.model.objects.filter(session_key=session_key).exists()
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in exists
      651.             return self.query.has_results(using=self.db)
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in has_results
      501.         return compiler.has_results()
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in has_results
      819.         return bool(self.execute_sql(SINGLE))
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
      837.             sql, params = self.as_sql()
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in as_sql
      389.             where, w_params = self.compile(self.where) if self.where is not None else ("", [])
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in compile
      366.             sql, params = node.as_sql(self, self.connection)
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/where.py" in as_sql
      79.                 sql, params = compiler.compile(child)
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in compile
      366.             sql, params = node.as_sql(self, self.connection)
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/lookups.py" in as_sql
      160.         rhs_sql = self.get_rhs_op(connection, rhs_sql)
    
    File "/usr/local/lib/python2.7/site-packages/django/db/models/lookups.py" in get_rhs_op
      164.         return connection.operators[self.lookup_name] % rhs
    
    File "/usr/local/lib/python2.7/site-packages/django_cassandra_engine/base/__init__.py" in __getattr__
      103.         raise AttributeError(attr)
    
    Exception Type: AttributeError at /auth/login/facebook/
    Exception Value: operators
    

Can somebody please tell me what am i doing wrong here?


Answer: You need to set `django_cassandra_engine` as secondary database backend:

    
    
    from cassandra import ConsistencyLevel
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        },
        'cassandra': {
            'ENGINE': 'django_cassandra_engine',
            'NAME': 'db',
            'USER': 'user',
            'PASSWORD': 'pass',
            'TEST_NAME': 'test_db',
            'HOST': '127.0.0.1',
            'OPTIONS': {
                'replication': {
                    'strategy_class': 'SimpleStrategy',
                    'replication_factor': 1
                },
                'connection': {
                    'consistency': ConsistencyLevel.LOCAL_ONE,
                    'retry_connect': True
                },
                'session': {
                    'default_timeout': 10,
                    'default_fetch_size': 10000
                    # + All options for cassandra.cluster.Session()
                }
            }
        }
    }
    

If you have plans for using f.ex. `django.contrib.auth` or
`django.contrib.admin`, then `django_cassandra_engine` has to be your
**secondary** database backend (not _default_ one).

Further instructions: <https://r4fek.github.io/django-cassandra-
engine/guide/advanced_usage/#cassandra-as-secondary-database>

