Skip to content

Commit d4d7e74

Browse files
author
Lars Solberg
committed
why import here
1 parent b5d5cf6 commit d4d7e74

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

api/data/opa/core/plugin.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@ def _get_plugindata():
353353
continue
354354

355355
logging.info(f'Loading plugin: {plugin.name}')
356+
357+
"""
358+
We should consider using lazy-loading instead of import_module.
359+
This line imports all .py files, which is problematic for example for tasks.
360+
If you import tasks inside an __init__, you will still need a get_component at
361+
top of tasks (to mark function as celery tasks). The get_component('celery') won't
362+
return anything, since everything is not ready yet.
363+
364+
Refactoring this code will probably be a no-go since there are many dependencies
365+
in eg the hooking system. Modules needs to be loaded
366+
"""
356367
mod = import_module(plugin.name)
357368

358369
if tasks_candidate:
@@ -430,7 +441,7 @@ def get_plugin_manager() -> PluginManager:
430441

431442
def get_component(name: str):
432443
try:
433-
return plugin_manager.optional_components[name]
444+
return plugin_manager.optional_components[name]
434445
except KeyError:
435446
raise Exception(
436447
f'Component is not defined (yet?). Defined components are: {list(plugin_manager.optional_components.keys())}'

0 commit comments

Comments
 (0)