Credentials Service Installation Error

Hi All,

To enable “View My Records”, I have enabled credentials service. The service is up and running but while accessing the URL it is throwing internal server error. Logs shows below error message. Not sure if anybody has faced similar issue earlier.

Traceback (most recent call last):
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 34, in inner
response = get_response(request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/utils/deprecation.py”, line 94, in call
response = response or self.get_response(request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 36, in inner
response = response_for_exception(request, exc)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File “/edx/app/credentials/credentials/credentials/apps/core/views.py”, line 125, in render_500
return render(request, template_name, status=500)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/shortcuts.py”, line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/loader.py”, line 62, in render_to_string
return template.render(context, request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/backends/django.py”, line 61, in render
return self.template.render(context)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/base.py”, line 169, in render
with context.bind_template(self):
File “/usr/lib/python3.8/contextlib.py”, line 113, in enter
return next(self.gen)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/context.py”, line 246, in bind_template
updates.update(processor(self.request))
File “/edx/app/credentials/credentials/credentials/apps/core/context_processors.py”, line 7, in core
site = request.site
AttributeError: ‘WSGIRequest’ object has no attribute ‘site’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/gunicorn/workers/base_async.py”, line 55, in handle
self.handle_request(listener_name, req, client, addr)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/gunicorn/workers/ggevent.py”, line 143, in handle_request
super().handle_request(listener_name, req, sock, addr)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/gunicorn/workers/base_async.py”, line 106, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/wsgi.py”, line 141, in call
response = self.get_response(request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/base.py”, line 75, in get_response
response = self._middleware_chain(request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 36, in inner
response = response_for_exception(request, exc)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File “/edx/app/credentials/credentials/credentials/apps/core/views.py”, line 125, in render_500
return render(request, template_name, status=500)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/shortcuts.py”, line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/loader.py”, line 62, in render_to_string
return template.render(context, request)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/backends/django.py”, line 61, in render
return self.template.render(context)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/base.py”, line 169, in render
with context.bind_template(self):
File “/usr/lib/python3.8/contextlib.py”, line 113, in enter
return next(self.gen)
File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/template/context.py”, line 246, in bind_template
updates.update(processor(self.request))
File “/edx/app/credentials/credentials/credentials/apps/core/context_processors.py”, line 7, in core
site = request.site
AttributeError: ‘WSGIRequest’ object has no attribute ‘site’

Thanks & Regards
Gaurav

Upon further investigation, it seems even though ansible reported that the installation is done and service is also running but credentials database was not created. Modified the playbook for native install to include credentials service and now seeing a different error during the installation

TASK [edx_django_service : migrate database] ***********************************
fatal: [localhost]: FAILED! => {“changed”: true, “cmd”: [“make”, “migrate”], “delta”: “0:00:00.533830”, “end”: “2021-02-16 16:17:35.927079”, “msg”: “non-zero return code”, “rc”: 2, “start”: “2021-02-16 16:17:35.393249”, “stderr”: “Traceback (most recent call last):\n File “manage.py”, line 15, in \n execute_from_command_line(sys.argv)\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/init.py”, line 381, in execute_from_command_line\n utility.execute()\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/init.py”, line 375, in execute\n self.fetch_command(subcommand).run_from_argv(self.argv)\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 323, in run_from_argv\n self.execute(*args, **cmd_options)\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 361, in execute\n self.check()\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 387, in check\n all_issues = self._run_checks(\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/commands/migrate.py”, line 64, in _run_checks\n issues = run_checks(tags=[Tags.database])\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/checks/registry.py”, line 72, in run_checks\n new_errors = check(app_configs=app_configs)\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/checks/database.py”, line 10, in check_database_backends\n issues.extend(conn.validation.check(**kwargs))\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/mysql/validation.py”, line 9, in check\n issues.extend(self._check_sql_mode(**kwargs))\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/mysql/validation.py”, line 13, in _check_sql_mode\n with self.connection.cursor() as cursor:\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 256, in cursor\n return self._cursor()\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 233, in _cursor\n self.ensure_connection()\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 217, in ensure_connection\n self.connect()\n File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 190, in connect\n self.close_at = None if max_age is None else time.time() + max_age\nTypeError: unsupported operand type(s) for +: ‘float’ and ‘str’\nmake: *** [Makefile:118: migrate] Error 1”, “stderr_lines”: [“Traceback (most recent call last):”, " File “manage.py”, line 15, in “, " execute_from_command_line(sys.argv)”, " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/init.py”, line 381, in execute_from_command_line", " utility.execute()", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/init.py”, line 375, in execute", " self.fetch_command(subcommand).run_from_argv(self.argv)", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 323, in run_from_argv", " self.execute(*args, **cmd_options)", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 361, in execute", " self.check()", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/base.py”, line 387, in check", " all_issues = self._run_checks(", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/management/commands/migrate.py”, line 64, in _run_checks", " issues = run_checks(tags=[Tags.database])", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/checks/registry.py”, line 72, in run_checks", " new_errors = check(app_configs=app_configs)", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/core/checks/database.py”, line 10, in check_database_backends", " issues.extend(conn.validation.check(**kwargs))", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/mysql/validation.py”, line 9, in check", " issues.extend(self._check_sql_mode(**kwargs))", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/mysql/validation.py”, line 13, in _check_sql_mode", " with self.connection.cursor() as cursor:", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 256, in cursor", " return self._cursor()", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 233, in _cursor", " self.ensure_connection()", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 217, in ensure_connection", " self.connect()", " File “/edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 190, in connect", " self.close_at = None if max_age is None else time.time() + max_age", “TypeError: unsupported operand type(s) for +: ‘float’ and ‘str’”, “make: *** [Makefile:118: migrate] Error 1”], “stdout”: “python manage.py migrate --noinput”, “stdout_lines”: [“python manage.py migrate --noinput”]}

Modifying the code in as below resolved the error and credentials service is working fine now.

change /edx/app/credentials/venvs/credentials/lib/python3.8/site-packages/django/db/backends/base/base.py

self.close_at = None if max_age is None else time.time() + max_age
to
self.close_at = None if max_age is None else time.time() + float (max_age)

Thanks & Regards
Gaurav