Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use django helper to validate manager and plugins paths

Maciej Korycinski52430087413e
diff --git a/saleor/core/extensions/checks.py b/saleor/core/extensions/checks.py
index 3b5cde6b87..9da8f0cec8 100644
--- a/saleor/core/extensions/checks.py
+++ b/saleor/core/extensions/checks.py
@@ -1,8 +1,8 @@
-import importlib
from typing import List
from django.conf import settings
from django.core.checks import Error, register
+from django.utils.module_loading import import_string
@register()
@@ -23,37 +23,22 @@ def check_manager(errors: List[Error]):
if not hasattr(settings, "EXTENSIONS_MANAGER") or not settings.EXTENSIONS_MANAGER:
errors.append(Error("Settings should contain EXTENSIONS_MANAGER env"))
return
- manager_path, _, manager_name = settings.EXTENSIONS_MANAGER.rpartition(".")
+
try:
- manager_module = importlib.import_module(manager_path)
- except ModuleNotFoundError:
- errors.append(Error("Extension Manager path: %s doesn't exist" % manager_path))
- else:
- manager_class = getattr(manager_module, manager_name, None)
- if not manager_class:
- errors.append(
- Error(
- "Extension Manager %s doesn't exists in specific path %s"
- % (manager_name, str(manager_module))
- )
+ import_string(settings.EXTENSIONS_MANAGER)
+ except ImportError:
+ errors.append(
+ Error(
+ "Extension Manager path: %s doesn't exist" % settings.EXTENSIONS_MANAGER
)
+ )
def check_single_plugin(plugin_path: str, errors: List[Error]):
if not plugin_path:
errors.append(Error("Wrong plugin_path %s" % plugin_path))
return
- plugin_path, _, plugin_name = plugin_path.rpartition(".")
try:
- plugin_module = importlib.import_module(plugin_path)
- except ModuleNotFoundError:
+ import_string(plugin_path)
+ except ImportError:
errors.append(Error("Plugin with path: %s doesn't exist" % plugin_path))
- else:
- plugin_class = getattr(plugin_module, plugin_name, None)
- if not plugin_class:
- errors.append(
- Error(
- "Plugin %s doesn't exists in specific path %s"
- % (plugin_name, str(plugin_module))
- )
- )