Failed upgrade to 0.14.4

Summary

Attempting an upgrade from Kolibri 0.14.3 to 0.14.4 with kolibri-server 0.3.8~beta2-0ubuntu1

Kolibri doesn’t start and I am getting this error in the log -

INFO 2020-11-26 18:00:36,351 cherrypy.access 192.168.1.1 - - "GET /api/auth/session/current/" 200 0 "http://server:8080/en/learn/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0"
ERROR 2020-11-26 18:00:36,772 django.request Internal Server Error: /api/auth/facility/
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.errors.CardinalityViolation: more than one row returned by a subquery used as an expression


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

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/viewsets.py", line 116, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "./kolibri/core/api.py", line 113, in list
    return Response(self.serialize(queryset))
  File "./kolibri/core/api.py", line 102, in serialize
    list(map(self._map_fields, self._serialize_queryset(queryset) or [])),
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/query.py", line 254, in __bool__
    self._fetch_all()
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/query.py", line 1121, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/query.py", line 106, in __iter__
    for row in compiler.results_iter(chunked_fetch=self.chunked_fetch):
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/sql/compiler.py", line 841, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/sql/compiler.py", line 899, in execute_sql
    raise original_exception
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/models/sql/compiler.py", line 889, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: more than one row returned by a subquery used as an expression

Technical details

  • Kolibri version - 0.14.4
  • Kolibri server - 0.3.8~beta2-0ubuntu1
  • Database - Postgres
  • Operating system - Ubuntu 18.04.3 LTS

hi @shrenik, according to your backtrace it seems the migration went well (without errors, but likely not so well) and this is happening when you try to access to the server with the browser. Please, correct me if I’m wrong.

The error seems to indicate there is some data corruption in one facility that has been synced. Can you confirm you have some facilities synced in that server?

Hi @jredrejo, Yes the above error appears in the log whenever a browser request is made to load Kolibri.
Yes, I have several facilities on this server which others sync with. Can you please guide me with the specific query that is failing? May be that shall help check the specific facility and clean up the corrupt data.

Yes, I think the failing query is this one:

SELECT DISTINCT "kolibriauth_collection"."id", "kolibriauth_collection"."name", "kolibriauth_collection"."dataset_id", "kolibriauth_facilitydataset"."learner_can_edit_username", "kolibriauth_facilitydataset"."learner_can_edit_name", "kolibriauth_facilitydataset"."learner_can_edit_password", "kolibriauth_facilitydataset"."learner_can_sign_up", "kolibriauth_facilitydataset"."learner_can_delete_account", "kolibriauth_facilitydataset"."learner_can_login_with_no_password", "kolibriauth_facilitydataset"."show_download_button_in_learn", "kolibriauth_facilitydataset"."description", "kolibriauth_facilitydataset"."location", "kolibriauth_facilitydataset"."registered", "kolibriauth_facilitydataset"."preset", (SELECT COUNT(id) FROM (SELECT U0."id", U0."_morango_dirty_bit", U0."_morango_source_id", U0."_morango_partition", U0."password", U0."last_login", U0."dataset_id", U0."username", U0."full_name", U0."date_joined", U0."facility_id", U0."gender", U0."birth_year", U0."id_number" FROM "kolibriauth_facilityuser" U0 WHERE U0."facility_id" = ("kolibriauth_collection"."id")) AS id__sum) AS "num_users", (SELECT COUNT(id) FROM (SELECT U0."id", U0."_morango_dirty_bit", U0."_morango_source_id", U0."_morango_partition", U0."dataset_id", U0."name", U0."parent_id", U0."kind", U0."lft", U0."rght", U0."tree_id", U0."level" FROM "kolibriauth_collection" U0 WHERE (U0."kind" = 'classroom' AND U0."parent_id" = ("kolibriauth_collection"."id"))) AS id__sum) AS "num_classrooms", (SELECT U0."last_activity_timestamp" FROM "morango_transfersession" U0 WHERE U0."filter" = (replace(CAST("kolibriauth_collection"."dataset_id" AS text), '-', '')) ORDER BY U0."last_activity_timestamp" DESC) AS "last_synced" FROM "kolibriauth_collection" INNER JOIN "kolibriauth_facilitydataset" ON ("kolibriauth_collection"."dataset_id" = "kolibriauth_facilitydataset"."id") WHERE ("kolibriauth_collection"."kind" = 'facility' AND "kolibriauth_collection"."kind" = 'facility');

The reason is failing is that one of the subqueries with (SELECT ....) AS ... is giving more than one result, and it should not. If you can find which one is, the data might be cleaned.

1 Like

Just for the record, fixed by the critical bug fix referenced at https://github.com/learningequality/kolibri/issues/7701 in 0.14.5 stable release.

@jredrejo thanks for prompt help.