1

An sql decode error is raised whenever I filter the groups in the admin module. I have made no modification to the admin interface or models regarding users or groups, except for a few one-to-one relationships with the user model. The error is only raised when filtering groups.
Is there any way to prevent this error from being raised?

The error is as is:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/auth/user/?groups__id__exact=1

Django Version: 2.2.10
Python Version: 3.8.1
Installed Applications:
['game.apps.GameConfig',
 'user.apps.UserConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
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']



Traceback:

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in parse
  824.                 return handler(self, statement)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in _select
  963.         self._query = SelectQuery(self.db, self.connection_properties, sm, self._params)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in __init__
  111.         super().__init__(*args)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in __init__
  72.         self.parse()

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in parse
  119.                 c = self.selected_columns = ColumnSelectConverter(self, tok_id)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/converters.py" in __init__
  44.         super().__init__(query_ref, begin_id)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/converters.py" in __init__
  24.         self.parse()

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/converters.py" in parse
  63.             raise SQLDecodeError

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

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/options.py" in wrapper
  606.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/options.py" in changelist_view
  1685.             cl = self.get_changelist_instance(request)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/options.py" in get_changelist_instance
  731.         return ChangeList(

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/views/main.py" in __init__
  82.         self.get_results(request)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/contrib/admin/views/main.py" in get_results
  210.         result_count = paginator.count

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/utils/functional.py" in __get__
  80.         res = instance.__dict__[self.name] = self.func(instance)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/core/paginator.py" in count
  91.             return c()

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/models/query.py" in count
  392.         return self.query.get_count(using=self.db)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/models/sql/query.py" in get_count
  504.         number = obj.get_aggregation(using, ['__count'])['__count']

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/models/sql/query.py" in get_aggregation
  489.         result = compiler.execute_sql(SINGLE)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1133.             cursor.execute(sql, params)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/backends/utils.py" in execute
  99.             return super().execute(sql, params)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/backends/utils.py" in execute
  67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  76.         return executor(sql, params, many, context)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/cursor.py" in execute
  48.         self.result = Result(

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in __init__
  753.         self.parse()

File "/Users/jayjay/anaconda3/envs/djongo/lib/python3.8/site-packages/djongo/sql2mongo/query.py" in parse
  846.                 raise exe from e

Exception Type: SQLDecodeError at /admin/auth/user/
Exception Value: FAILED SQL: SELECT COUNT(*) FROM (SELECT DISTINCT "auth_user"."id" AS Col1, "auth_user"."password" AS Col2, "auth_user"."last_login" AS Col3, "auth_user"."is_superuser" AS Col4, "auth_user"."username" AS Col5, "auth_user"."first_name" AS Col6, "auth_user"."last_name" AS Col7, "auth_user"."email" AS Col8, "auth_user"."is_staff" AS Col9, "auth_user"."is_active" AS Col10, "auth_user"."date_joined" AS Col11 FROM "auth_user" INNER JOIN "auth_user_groups" ON ("auth_user"."id" = "auth_user_groups"."user_id") WHERE "auth_user_groups"."group_id" = %(0)s) subquery
Params: (1,)
Version: 1.3.1

Here is the output of pip freeze:

certifi==2019.11.28
dataclasses==0.6
Django==2.2.10
django-jsoneditor==0.1.5
djongo==1.3.1
jsonfield==3.1.0
packaging==20.1
pymongo==3.10.1
pyparsing==2.4.6
python-dateutil==2.8.1
pytz==2019.3
six==1.14.0
sqlparse==0.2.4
3
  • Is that the full error message? Commented Mar 1, 2020 at 23:19
  • What does MongoDb have to do with it? Commented Mar 1, 2020 at 23:46
  • You've made a nice statement, but haven't asked a question. Additionally, you should consider proving the error message from your application. Commented Mar 2, 2020 at 0:48

1 Answer 1

1

Here's a temporary hack that I found:
I changed line 753 in djongo/sql2mongo/query.py from this:

        self.parse()

to this:

        try:
            self.parse()
        except:
            if (self._sql.strip().endswith("subquery")):
                self._sql = self._sql.strip()[:-8]
Sign up to request clarification or add additional context in comments.

1 Comment

Did you override the BaseQuery class there, and how?

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.