0

I have been experimenting with mongodb with Django. I created a super user, and then proceeded to http://localhost:8000/admin/ to login. Upon entering my credentials, and submitting them, the error given at the end of this post occurred. I have 2 other apps in this project and have also commented the line where the admin can register the model in appname/admin.py, i.e.:

#admin.site.register(Tweet)

How can I fix this? If you would like any further information about the code or from certain files please let me know and I will edit it in :)

I assume the error is caused with the way mongo and django is workign together but have no idea how to correct it.

I am sure the python installation, and routes all work correctly as they were configured with the assistance of the department admins.

NOTE: some of the routes are due to custom installation of Python in case it seems extremely weird. I am using a Department machine to do my work, hence the paths.

Relevant Versions of modules/software:

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

  • python (3.6.4)
  • Django (2.0.3)
  • MongoDB shell version: (2.6.12)
  • mongod --version results in: db version v2.6.12
  • pymongo (3.6.1)
  • sqlparse (0.2.4)
  • djongo (1.2.23)

Db code in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'hamish-djongo-db',
        'USER': 'hamish_admin',
        'PASSWORD': 'thishasbeencensoredfortheinternet',
    }
}

Error in shell:

Internal Server Error: /admin/
Traceback (most recent call last):
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 454, in __iter__
    yield from iter(self._query)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 144, in __iter__
    self._cursor = self._get_cursor()
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 229, in _get_cursor
    cur = self.db_ref[self.left_table].aggregate(pipeline)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/collection.py", line 2185, in aggregate
    **kwargs)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/collection.py", line 2092, in _aggregate
    client=self.__database.client)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/pool.py", line 517, in command
    collation=collation)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/network.py", line 125, in command
    parse_write_concern_error=parse_write_concern_error)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/helpers.py", line 145, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: exception: Unrecognized pipeline stage name: '$lookup'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 158, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
    response = response.render()
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 943, in render
    bit = node.render_annotated(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
    return self.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py", line 155, in render
    return compiled_parent._render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 943, in render
    bit = node.render_annotated(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
    return self.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py", line 155, in render
    return compiled_parent._render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 943, in render
    bit = node.render_annotated(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
    return self.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py", line 67, in render
    result = block.nodelist.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 943, in render
    bit = node.render_annotated(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
    return self.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/defaulttags.py", line 314, in render
    return nodelist.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 943, in render
    bit = node.render_annotated(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
    return self.render(context)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/defaulttags.py", line 168, in render
    len_values = len(values)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py", line 254, in __len__
    self._fetch_all()
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py", line 1179, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py", line 62, in __iter__
    for row in compiler.results_iter(results):
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1460, in cursor_iter
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1460, in <lambda>
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/utils.py", line 96, in inner
    return func(*args, **kwargs)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/cursor.py", line 59, in fetchmany
    ret.append(self.result.next())
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 448, in __next__
    return next(self._result_generator)
  File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 466, in __iter__
    raise exe from e
djongo.sql2mongo.SQLDecodeError: FAILED SQL: SELECT "django_admin_log"."id", "django_admin_log"."action_time", "django_admin_log"."user_id", "django_admin_log"."content_type_id", "django_admin_log"."object_id", "django_admin_log"."object_repr", "django_admin_log"."action_flag", "django_admin_log"."change_message", "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined", "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_admin_log" INNER JOIN "auth_user" ON ("django_admin_log"."user_id" = "auth_user"."id") LEFT OUTER JOIN "django_content_type" ON ("django_admin_log"."content_type_id" = "django_content_type"."id") WHERE "django_admin_log"."user_id" = %(0)s ORDER BY "django_admin_log"."action_time" DESC LIMIT 10
Pymongo error: OrderedDict([('errmsg', "exception: Unrecognized pipeline stage name: '$lookup'"), ('code', 16436), ('ok', 0.0)])
Version: 1.2.23
[29/Mar/2018 12:42:09] "GET /admin/ HTTP/1.1" 500 339290

Error on page:

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/

Django Version: 2.0.3
Python Version: 3.6.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'widget_tweaks',
 'blogtest',
 'tweetish']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /dcs/14/u1404526/.local/lib/python3.6/site-packages/django/contrib/admin/templates/admin/base.html, error at line 0
   FAILED SQL: SELECT "django_admin_log"."id", "django_admin_log"."action_time", "django_admin_log"."user_id", "django_admin_log"."content_type_id", "django_admin_log"."object_id", "django_admin_log"."object_repr", "django_admin_log"."action_flag", "django_admin_log"."change_message", "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined", "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_admin_log" INNER JOIN "auth_user" ON ("django_admin_log"."user_id" = "auth_user"."id") LEFT OUTER JOIN "django_content_type" ON ("django_admin_log"."content_type_id" = "django_content_type"."id") WHERE "django_admin_log"."user_id" = %(0)s ORDER BY "django_admin_log"."action_time" DESC LIMIT 10
Pymongo error: OrderedDict([('errmsg', "exception: Unrecognized pipeline stage name: '$lookup'"), ('code', 16436), ('ok', 0.0)])
Version: 1.2.23
   1 : {% load i18n static %}<!DOCTYPE html>
   2 : {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
   3 : <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
   4 : <head>
   5 : <title>{% block title %}{% endblock %}</title>
   6 : <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" />
   7 : {% block extrastyle %}{% endblock %}
   8 : {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %}
   9 : {% block extrahead %}{% endblock %}
   10 : {% block responsive %}


Traceback:

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __iter__
  454.             yield from iter(self._query)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __iter__
  144.             self._cursor = self._get_cursor()

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in _get_cursor
  229.             cur = self.db_ref[self.left_table].aggregate(pipeline)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/collection.py" in aggregate
  2185.                                    **kwargs)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/collection.py" in _aggregate
  2092.                 client=self.__database.client)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/pool.py" in command
  517.                            collation=collation)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/network.py" in command
  125.                 parse_write_concern_error=parse_write_concern_error)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/pymongo/helpers.py" in _check_command_response
  145.             raise OperationFailure(msg % errmsg, code, response)

The above exception (exception: Unrecognized pipeline stage name: '$lookup') was the direct cause of the following exception:

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  158.                 response = self.process_exception_by_middleware(e, request)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  156.                 response = response.render()

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/response.py" in rendered_content
  83.         content = template.render(context, self._request)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  175.                     return self._render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  155.             return compiled_parent._render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  155.             return compiled_parent._render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  67.                 result = block.nodelist.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/defaulttags.py" in render
  314.                 return nodelist.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/template/defaulttags.py" in render
  168.             len_values = len(values)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py" in __len__
  254.         self._fetch_all()

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
  1179.             self._result_cache = list(self._iterable_class(self))

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
  62.         for row in compiler.results_iter(results):

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in cursor_iter
  1460.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in <lambda>
  1460.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/django/db/utils.py" in inner
  96.                 return func(*args, **kwargs)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/cursor.py" in fetchmany
  59.                 ret.append(self.result.next())

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __next__
  448.         return next(self._result_generator)

File "/dcs/14/u1404526/.local/lib/python3.6/site-packages/djongo/sql2mongo/query.py" in __iter__
  466.             raise exe from e

Exception Type: SQLDecodeError at /admin/
Exception Value: FAILED SQL: SELECT "django_admin_log"."id", "django_admin_log"."action_time", "django_admin_log"."user_id", "django_admin_log"."content_type_id", "django_admin_log"."object_id", "django_admin_log"."object_repr", "django_admin_log"."action_flag", "django_admin_log"."change_message", "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined", "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_admin_log" INNER JOIN "auth_user" ON ("django_admin_log"."user_id" = "auth_user"."id") LEFT OUTER JOIN "django_content_type" ON ("django_admin_log"."content_type_id" = "django_content_type"."id") WHERE "django_admin_log"."user_id" = %(0)s ORDER BY "django_admin_log"."action_time" DESC LIMIT 10
Pymongo error: OrderedDict([('errmsg', "exception: Unrecognized pipeline stage name: '$lookup'"), ('code', 16436), ('ok', 0.0)])
Version: 1.2.23
2

4 Answers 4

0

thanks to @oluwafemi-sule comment, the problem has been corrected.

I have updated to Mongo 3.6.3 to resolve this issue.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe try upgrading Django to version 3.1.7 or above. I got an SQLDecodeError when I tried to migrate and I solved it by upgrading Django and running makemigrations again before migrating. The previous Django version that I had was 2.1.7 and apparently the migration file generated by these two versions are very different.

Comments

0

I downgraded my django version to 3.2 and it worked for me.

pip install django==3.2

Comments

-3

Error: "djongo.sql2mongo.SQLDecodeError: FAILED SQL: SELECT"

Solution: Here you can simply see that SQL is failed, hence first install mysqlclient and then run the command.

sudo apt-get install mysql-client

Reason: Pymongo wants to convert sql(Default query language) query to mongoDB query but unable to process it because of missing mysql pluggins.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.