Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot enable learn plugin #186

Closed
indirectlylit opened this issue Jun 29, 2016 · 5 comments
Closed

cannot enable learn plugin #186

indirectlylit opened this issue Jun 29, 2016 · 5 comments
Assignees

Comments

@indirectlylit
Copy link
Contributor

Steps to repo:

  • rename your kolibri settings file
    • (e.g. from ~/.kolibri/kolibri_settings.json to ~/.kolibri/kolibri_settings.json.backup)
  • run kolibri plugin kolibri.plugins.learn enable

I get

Traceback (most recent call last):
  File "/Users/d/PythonEnvs/kolibri/bin/kolibri", line 9, in <module>
    load_entry_point('kolibri', 'console_scripts', 'kolibri')()
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/utils/cli.py", line 268, in main
    plugin(plugin_name, **arguments)
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/utils/cli.py", line 204, in plugin
    plugin_module = importlib.import_module(plugin_name + ".kolibri_plugin")
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/learn/kolibri_plugin.py", line 8, in <module>
    from . import hooks, urls
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/learn/urls.py", line 3, in <module>
    from . import views
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/learn/views.py", line 4, in <module>
    from kolibri.content.api import get_top_level_topics
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/content/api.py", line 6, in <module>
    from kolibri.content import models as KolibriContent
  File "/Users/d/Projects/learning_equality/repos/kolibri/kolibri/content/models.py", line 13, in <module>
    from mptt.models import MPTTModel, TreeForeignKey
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/mptt/models.py", line 379, in <module>
    class MPTTModel(six.with_metaclass(MPTTModelBase, models.Model)):
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/django/utils/six.py", line 808, in __new__
    return meta(name, bases, d)
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/mptt/models.py", line 262, in __new__
    cls = super_new(meta, class_name, bases, class_dict)
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/Users/d/PythonEnvs/kolibri/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Workaround for new Kolibri check-outs:

manually set your settings file to:

{"FIRST_RUN": false, "AUTO_SEARCH_PLUGINS": ["some.plugin.module.path"], "INSTALLED_APPS": ["kolibri.plugins.management", "kolibri.plugins.learn", "kolibri.plugins.document_pdf_render", "kolibri.plugins.video_mp4_render", "kolibri.plugins.audio_mp3_render"]}
@jamalex
Copy link
Member

jamalex commented Jul 5, 2016

Fixed in 3206d43

@benjaoming
Copy link
Contributor

benjaoming commented May 30, 2017

Two options:

  1. Running django.setup() before enabling/disabling a plugin (in kolibri.utils.cli.plugin). That way, we just know that the django stack is ready when loading kolibri_plugin which requires less carefulness when writing plugins.

  2. Moving the import of urls modules to MyKolibriPlugin.url_module. This way, we know that loading kolibri_plugin is less error prone because it doesn't depend on a functional django stack. So for instance if a plugin has broken something in the Django stack (for instance its views or models are invalid), we can still enable/disable the plugin.

@benjaoming benjaoming reopened this May 30, 2017
@benjaoming
Copy link
Contributor

benjaoming commented May 30, 2017

I'm wondering if option 2 is too restrictive. That way, a plugin cannot access its own models when it's being enabled. On the other hand, things like migrations may not have been fired.

Can anybody advice on what plugins currently HAVE to be able to do when enabled? I can't see that any of the core plugins have custom enable() class methods anyways.

@benjaoming
Copy link
Contributor

I'm wondering if option 1 is too restrictive. That way, a plugin cannot access its own models when it's being enabled. On the other hand, things like migrations may not have been fired.

Following up on this: Since one may run enable->disable->enable, with each operation starting and exiting Kolibri, I believe that plugins should not make lots of assumptions about initial states while running enable. This is just a caution.

Anyways, because commands such as collectstatic and migrate have to be run, we also have to run django.setup() anyways.

Here's a rough vision of what enabling a plugin could look like:

$ kolibri plugin enable kolibri.plugins.learn

Enabling plugin: kolibri.plugins.learn

Verifying dependencies... OK!
Collecting static assets (JS/CSS/images)........ OK!
Running database migrations............ OK!

Plugin enabled. Please start/restart Kolibri.

@benjaoming
Copy link
Contributor

Replacing this issue with #2510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants