Learn more about these different git repos.
Other Git URLs
6aa5e8f
97171f7
@@ -29,6 +29,8 @@
hubs.widgets.registry.register_list(hubs.app.app.config["WIDGETS"])
for w_instance in session.query(hubs.models.Widget).all():
+ if not w_instance.enabled:
+ continue
for fn_name, fn_class in w_instance.module.get_cached_functions().items():
if fn_class(w_instance).is_cached():
full += 1
@@ -91,6 +91,8 @@
# Get a list of all our widgets:
log.debug("Querying for all widgets.")
widgets = session.query(hubs.models.Widget).all()
+ # Filter out widgets that have been disabled.
+ widgets = [w for w in widgets if w.enabled]
# Randomize so that all the triage daemons work on widgets in different
# orders. This should hopefully prevent cache thrashing.
log.debug("Randomizing list of all widgets.")
@@ -456,6 +456,10 @@
def edit_url(self):
return self.module.get_edit_url(self.hub, self)
+ @property
+ def enabled(self):
+ return self.plugin in hubs.widgets.registry
+
class User(BASE):
__tablename__ = 'users'
@@ -0,0 +1,28 @@
+ from __future__ import unicode_literals
+ from hubs.app import app
+ from hubs.backend import triage
+ from hubs.models import Hub, Widget
+ from hubs.tests import APPTest
+ class TriageTest(APPTest):
+ def setUp(self):
+ super(TriageTest, self).setUp()
+ # Set the session
+ triage.session = self.session
+ def test_get_widgets(self):
+ # Get all widgets except those whose module isn't installed.
+ hub = Hub.by_name('ralph')
+ widget = Widget(
+ plugin='non-existant',
+ index=500,
+ _config="{}",
+ )
+ hub.widgets.append(widget)
+ module_names = [w.plugin for w in triage.get_widgets()]
+ self.assertNotIn("non-existant", module_names)
+ self.assertEqual(len(module_names), 59)
@@ -229,3 +229,9 @@
widget.visibility = "restricted"
self.assertEqual(
widget._get_auth_permission_name("view"), "widget.restricted.view")
+ def test_widget_enabled(self):
+ hub = hubs.models.Hub.get("ralph")
+ widget = hubs.models.Widget(hub=hub, plugin="does-not-exist")
+ self.session.add(widget)
+ self.assertFalse(widget.enabled)
@@ -27,6 +27,8 @@
def do_list(args):
''' List the different widget for which there is data cached. '''
widget = w_instance.module
for fn_name, fn_class in widget.get_cached_functions().items():
When a widget is disabled, the DB instances should be ignored by the backend. Otherwise the module can't be imported and it's a crash.
LGTM, though I recommend tests for these changes.
You're right. We currently don't have tests for the backend daemons, so it's a good opportunity to add some.
rebased
Done! :-)
Pull-Request has been merged by abompard
When a widget is disabled, the DB instances should be ignored by the backend. Otherwise the module can't be imported and it's a crash.