Repository: learningequality/kolibri
Issue: get_device_setting may return None

### Observed behavior

We received a traceback in a log file (see below).

@rtibbles notes:

> for the latter file that was posted looks like my refactor of the device settings code has introduced a regression - it doesn't seem to be returning the default when the settings are `None` inside `get_device_setting`

### Expected behavior

API works

### User-facing consequences

Not sure

### Errors and logs

```
ERROR 2020-01-20 09:14:54,827 exception Internal Server Error: /api/
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 "./kolibri/core/device/middleware.py", line 60, in __call__
    path_valid = is_valid_path(language_path, urlconf)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/base.py", line 158, in is_valid_path
    resolve(path, urlconf)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/base.py", line 27, in resolve
    return get_resolver(urlconf).resolve(path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 366, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 366, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 366, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 366, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 366, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/urls/resolvers.py", line 361, in resolve
    match = self.regex.search(path)
  File "./kolibri/core/device/translation.py", line 154, in regex
    device_language = get_device_language() or get_settings_language()
  File "./kolibri/core/device/translation.py", line 25, in get_device_language
    language_id = get_device_setting("language_id", None)
  File "./kolibri/core/device/utils.py", line 25, in get_device_setting
    return getattr(device_settings, setting)
AttributeError: 'NoneType' object has no attribute 'language_id'
```

### Steps to reproduce

n/a

### Context

A complicated upgrade with migration issues affecting the `device_devicesettings` table

Changed files:
kolibri/core/device/utils.py

diff --git a/kolibri/core/device/utils.py b/kolibri/core/device/utils.py
index b9bba93e57..0663706068 100644
--- a/kolibri/core/device/utils.py
+++ b/kolibri/core/device/utils.py
@@ -22,6 +22,8 @@ def get_device_setting(setting, default=no_default_value):
 
     try:
         device_settings = DeviceSettings.objects.get()
+        if device_settings is None:
+            raise DeviceSettings.DoesNotExist
         return getattr(device_settings, setting)
     except (DeviceSettings.DoesNotExist, OperationalError, ProgrammingError):
         if default is not no_default_value: