Catch import error when text is used as a reason instead of path
authorBoris Bobrov <breton@cynicmansion.ru>
Tue, 23 Feb 2016 00:57:00 +0000 (03:57 +0300)
committerBoris Bobrov <breton@cynicmansion.ru>
Tue, 23 Feb 2016 00:57:00 +0000 (03:57 +0300)
fail_error was used in import, but due to some changes text could appear
there and it caused an error.

There is little sense now to remove these text messages because they are
probably in databases already, so just ignore import errors.

mediagoblin/db/mixin.py

index 083617d3c1c47b7c1a404b61310f99323213a0a5..c8c5f95c13dbddb5aaf630fbfffdfd9410f9bff5 100644 (file)
@@ -330,7 +330,17 @@ class MediaEntryMixin(GenerateSlugMixin, GeneratePublicIDMixin):
         Get the exception that's appropriate for this error
         """
         if self.fail_error:
-            return common.import_component(self.fail_error)
+            try:
+                return common.import_component(self.fail_error)
+            except ImportError:
+                # TODO(breton): fail_error should give some hint about why it
+                # failed. fail_error is used as a path to import().
+                # Unfortunately, I didn't know about that and put general error
+                # message there. Maybe it's for the best, because for admin,
+                # we could show even some raw python things. Anyway, this
+                # should be properly resolved. Now we are in a freeze, that's
+                # why I simply catch ImportError.
+                return self.fail_error
 
     def get_license_data(self):
         """Return license dict for requested license"""