Repository: learningequality/kolibri

Issue:
Empty container showing when I import a channel
### Observed behavior
There is an empty container showing when I import a channel. 

### Expected behavior
That container should not show if it's empty

### User-facing consequences
<!--
Implications and real-world consequences for learners, coaches, admins, and other users of the application
-->

…

### Errors and logs
![Screen Shot 2019-05-23 at 12 08 52 PM](https://user-images.githubusercontent.com/8663934/58225284-e2a91480-7d53-11e9-8ff1-4fff2639b180.png)

<--
Please wrap errors in triple backticks for clean formatting like this:
```
01:10 info: something happened
01:12 error: something bad happened
```
-->

…

### Steps to reproduce
* Using an admin account
* Select and import a channel 
* The empty container will show up in a few seconds

### Context
Tell us about your environment, including:

* Kolibri version: v0.12.4-beta3
* Operating system: Windows 7
* Browser: Firefox 67.0


Discussion:
Isn't that just the container, before the content inside is loaded? 

![Ubuntu16 04 (0 12 4-b3)  Running  - Oracle VM VirtualBox_050](https://user-images.githubusercontent.com/1457929/58225781-09e7ed80-7d24-11e9-8b4f-e992b1b3c177.png)


Does the channel content appear at all, or you're just stuck at that point? Any errors in logs, Console...?

The channel properly loaded in a few seconds with no javascript error. It's just that empty container showing when you import a channel.
@mrpau-richard could you please fill out the rest of the issue template?

Resolving patch:
diff --git a/kolibri/core/content/utils/channel_import.py b/kolibri/core/content/utils/channel_import.py
--- a/kolibri/core/content/utils/channel_import.py
+++ b/kolibri/core/content/utils/channel_import.py
@@ -797,3 +797,5 @@ def import_channel_from_local_db(channel_id, cancel_check=None):
             id=node_id, title=channel.name, content_id=node_id, channel_id=channel_id
         )
     channel.save()
+
+    logger.info("Channel {} successfully imported into the database".format(channel_id))
diff --git a/kolibri/core/tasks/storage.py b/kolibri/core/tasks/storage.py
--- a/kolibri/core/tasks/storage.py
+++ b/kolibri/core/tasks/storage.py
@@ -18,6 +18,8 @@
 
 Base = declarative_base()
 
+logger = logging.getLogger(__name__)
+
 
 class ORMJob(Base):
     """
@@ -117,7 +119,7 @@ def enqueue_job(self, j, queue):
             try:
                 session.commit()
             except Exception as e:
-                logging.error("Got an error running session.commit(): {}".format(e))
+                logger.error("Got an error running session.commit(): {}".format(e))
 
             return j.job_id
 
@@ -244,25 +246,37 @@ def save_job_meta(self, job):
 
     def _update_job(self, job_id, state=None, **kwargs):
         with self.session_scope() as session:
-
-            job, orm_job = self._get_job_and_orm_job(job_id, session)
-
-            # Note (aron): looks like SQLAlchemy doesn't automatically
-            # save any pickletype fields even if we re-set (orm_job.obj = job) that
-            # field. My hunch is that it's tracking the id of the object,
-            # and if that doesn't change, then SQLAlchemy doesn't repickle the object
-            # and save to the DB.
-            # Our hack here is to just copy the job object, and then set thespecific
-            # field we want to edit, in this case the job.state. That forces
-            # SQLAlchemy to re-pickle the object, thus setting it to the correct state.
-            job = copy(job)
-            if state is not None:
-                orm_job.state = job.state = state
-            for kwarg in kwargs:
-                setattr(job, kwarg, kwargs[kwarg])
-            orm_job.obj = job
-            session.add(orm_job)
-            return job, orm_job
+            try:
+                job, orm_job = self._get_job_and_orm_job(job_id, session)
+                # Note (aron): looks like SQLAlchemy doesn't automatically
+                # save any pickletype fields even if we re-set (orm_job.obj = job) that
+                # field. My hunch is that it's tracking the id of the object,
+                # and if that doesn't change, then SQLAlchemy doesn't repickle the object
+                # and save to the DB.
+                # Our hack here is to just copy the job object, and then set thespecific
+                # field we want to edit, in this case the job.state. That forces
+                # SQLAlchemy to re-pickle the object, thus setting it to the correct state.
+                job = copy(job)
+                if state is not None:
+                    orm_job.state = job.state = state
+                for kwarg in kwargs:
+                    setattr(job, kwarg, kwargs[kwarg])
+                orm_job.obj = job
+                session.add(orm_job)
+                return job, orm_job
+            except JobNotFound:
+                if state:
+                    logger.error(
+                        "Tried to update job with id {} with state {} but it was not found".format(
+                            job_id, state
+                        )
+                    )
+                else:
+                    logger.error(
+                        "Tried to update job with id {} but it was not found".format(
+                            job_id
+                        )
+                    )
 
     def _get_job_and_orm_job(self, job_id, session):
         orm_job = session.query(ORMJob).filter_by(id=job_id).one_or_none()


Test patch: