Repository: learningequality/kolibri

Issue:
progress remains at 0% until completion when using bulk import

### Observed behavior

For each individual channel, the progress jumps from 0 to 100% when importing using the whole-channel bulk import function.

### Expected behavior

Progress is shown for each channel

### User-facing consequences

It looks like the import is frozen, even though it's actually working fine

### Errors and logs

None

### Steps to reproduce

Use bulk import and look at progress

### Context

* 0.12.1
* dev server



Discussion:
@jonboiser would you mind taking a look at this?

Resolving patch:
diff --git a/kolibri/core/tasks/api.py b/kolibri/core/tasks/api.py
--- a/kolibri/core/tasks/api.py
+++ b/kolibri/core/tasks/api.py
@@ -66,7 +66,7 @@ def validate_content_task(request, task_description, require_channel=False):
     try:
         channel_id = task_description["channel_id"]
     except KeyError:
-        raise serializers.ValidationError("The channel_ids field is required.")
+        raise serializers.ValidationError("The channel_id field is required.")
 
     channel_name = get_channel_name(channel_id, require_channel)
 
@@ -233,7 +233,7 @@ def startremotebulkimport(self, request):
         job_ids = []
 
         for task in tasks:
-            task.update({"type": "REMOTEIMPORT"})
+            task.update({"type": "REMOTEIMPORT", "database_ready": False})
             import_job_id = queue.enqueue(
                 _remoteimport,
                 task["channel_id"],
@@ -241,6 +241,7 @@ def startremotebulkimport(self, request):
                 peer_id=task["peer_id"],
                 extra_metadata=task,
                 cancellable=True,
+                track_progress=True,
             )
             job_ids.append(import_job_id)
 
@@ -305,7 +306,7 @@ def startdiskbulkimport(self, request):
         job_ids = []
 
         for task in tasks:
-            task.update({"type": "DISKIMPORT"})
+            task.update({"type": "DISKIMPORT", "database_ready": False})
             import_job_id = queue.enqueue(
                 _diskimport,
                 task["channel_id"],
@@ -454,7 +455,6 @@ def startdiskbulkexport(self, request):
     def startdiskexport(self, request):
         """
         Export a channel to a local drive, and copy content to the drive.
-
         """
 
         task = validate_local_export_task(request, request.data)
@@ -481,7 +481,6 @@ def startdiskexport(self, request):
     def startdataportalsync(self, request):
         """
         Initiate a PUSH sync with Kolibri Data Portal.
-
         """
         task = {
             "facility": request.data["facility"],
@@ -697,11 +696,19 @@ def _remoteimport(
         check_for_cancel=check_for_cancel,
     )
 
-    # Add the channel name if it wasn't added initially
+    # Make some real-time updates to the metadata
     job = get_current_job()
+
+    # Signal to UI that the DB-downloading step is done so it knows to display
+    # progress correctly
+    job.update_progress(0, 1.0)
+    job.extra_metadata["database_ready"] = True
+
+    # Add the channel name if it wasn't added initially
     if job and job.extra_metadata.get("channel_name", "") == "":
         job.extra_metadata["channel_name"] = get_channel_name(channel_id)
-        job.save_meta()
+
+    job.save_meta()
 
     # Skip importcontent step if updating and no nodes have changed
     if is_updating and (node_ids is not None) and len(node_ids) == 0:
@@ -741,11 +748,19 @@ def _diskimport(
         check_for_cancel=check_for_cancel,
     )
 
-    # Add the channel name if it wasn't added initially
+    # Make some real-time updates to the metadata
     job = get_current_job()
+
+    # Signal to UI that the DB-downloading step is done so it knows to display
+    # progress correctly
+    job.update_progress(0, 1.0)
+    job.extra_metadata["database_ready"] = True
+
+    # Add the channel name if it wasn't added initially
     if job and job.extra_metadata.get("channel_name", "") == "":
         job.extra_metadata["channel_name"] = get_channel_name(channel_id)
-        job.save_meta()
+
+    job.save_meta()
 
     # Skip importcontent step if updating and no nodes have changed
     if is_updating and (node_ids is not None) and len(node_ids) == 0:


Test patch: