learningequality / kolibri

Kolibri Learning Platform: the offline app for universal education
https://learningequality.org/kolibri/
MIT License
819 stars 695 forks source link

Kolibri develop: Disabled plugins are still being considered in redirects #9696

Closed manuq closed 2 years ago

manuq commented 2 years ago

Disabling the Learn plugin doesn't unregister the LearnRedirect hook. Which results in the traceback below. Note that we have a similar plugin with aredirect hook for the same roles, however it's URL is not being returned by the get_url_by_role() function in kolibri.core.views.

Errors and logs

09-06 22:49:09.662 22461 22592 I python  : INFO     127.0.0.1 - - "GET /" 302 0 "" "Mozilla/5.0 (Linux; Android 12; sdk_gpc_x86_64 Build/SE2B.220326.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/95.0.4638.74 Safari/537.36"
09-06 22:49:09.689 22461 22486 D EGL_emulation: app_time_stats: avg=38.40ms min=10.08ms max=84.93ms count=26
09-06 22:49:09.750 22461 22591 I python  : ERROR    Internal Server Error: /en/
09-06 22:49:09.750 22461 22591 I python  : Traceback (most recent call last):
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/urls/base.py", line 77, in reverse
09-06 22:49:09.750 22461 22591 I python  : KeyError: 'kolibri.plugins.learn'
09-06 22:49:09.750 22461 22591 I python  :
09-06 22:49:09.750 22461 22591 I python  : During handling of the above exception, another exception occurred:
09-06 22:49:09.750 22461 22591 I python  :
09-06 22:49:09.750 22461 22591 I python  : Traceback (most recent call last):
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/exception.py", line 41, in inner
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/base.py", line 187, in _get_response
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/core/handlers/base.py", line 185, in _get_response
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/views/generic/base.py", line 68, in view
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/views/generic/base.py", line 88, in dispatch
09-06 22:49:09.750 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 158, in get
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 103, in get_url_by_role
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/views.py", line 107, in <genexpr>
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/plugins/learn/kolibri_plugin.py", line 46, in url
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/core/hooks.py", line 45, in plugin_url
09-06 22:49:09.751 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/plugins/utils/__init__.py", line 54, in plugin_url
09-06 22:49:09.752 22461 22591 I python  :   File "/sysroot/home/manuq/eos/hack/gitrepos/kolibri-installer-android/src/kolibri/dist/django/urls/base.py", line 82, in reverse
09-06 22:49:09.752 22461 22591 I python  : django.urls.exceptions.NoReverseMatch: 'kolibri.plugins.learn' is not a registered namespace inside 'kolibri'
09-06 22:49:09.775 22461 22591 I python  : INFO     127.0.0.1 - - "GET /en/" 500 0 "" "Mozilla/5.0 (Linux; Android 12; sdk_gpc_x86_64 Build/SE2B.220326.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/95.0.4638.74 Safari/537.36"
rtibbles commented 2 years ago

Flagging that I am unable to replicate this when the disabling is done from the command line. @manuq can you paste the script you currently have for when the disabling is happening?

manuq commented 2 years ago

@rtibbles sorry for the delayed answer. I just tried and I also can't replicate it through the command line.

Our current script is hard to follow, but it basically disables the Learn plugin here and later in execution (after some user intervention) Kolibri starts here

By the way we have a silly temporary patch. So this is not blocking us.

rtibbles commented 2 years ago

The only thing I can think of is if one of the imports from kolibri is somehow setting off the hook registration - but then that should only be happening when the plugins are also registered, which would then give you the runtime error you had seen before.

The link to the script may help with replication though, thanks!

rtibbles commented 2 years ago

So, the issue appears to be that disabling a plugin also has the unintended side effect of registering its hooks. This doesn't have any effect from the CLI, as it's only registered in memory, but is appearing here. I think I know how to fix this.

manuq commented 2 years ago

@rtibbles thanks so much. I have confirmed that the PR above fixes the issue.