{"record":{"id":"4cde1a4f05bac522","repo":"microsoft/qlib","slug":"none-is-passed-in-as-parameters-as-module-path","errorCode":null,"errorMessage":"None is passed in as parameters as module_path","messagePattern":"None is passed in as parameters as module_path","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"qlib/utils/mod.py","lineNumber":33,"sourceCode":"import re\nimport sys\nfrom types import ModuleType\nfrom typing import Any, Dict, List, Tuple, Union\nfrom urllib.parse import urlparse\n\nfrom qlib.typehint import InstConf\nfrom qlib.utils.pickle_utils import restricted_pickle_load\n\n\ndef get_module_by_module_path(module_path: Union[str, ModuleType]):\n    \"\"\"Load module path\n\n    :param module_path:\n    :return:\n    :raises: ModuleNotFoundError\n    \"\"\"\n    if module_path is None:\n        raise ModuleNotFoundError(\"None is passed in as parameters as module_path\")\n\n    if isinstance(module_path, ModuleType):\n        module = module_path\n    else:\n        if module_path.endswith(\".py\"):\n            module_name = re.sub(\"^[^a-zA-Z_]+\", \"\", re.sub(\"[^0-9a-zA-Z_]\", \"\", module_path[:-3].replace(\"/\", \"_\")))\n            module_spec = importlib.util.spec_from_file_location(module_name, module_path)\n            module = importlib.util.module_from_spec(module_spec)\n            sys.modules[module_name] = module\n            module_spec.loader.exec_module(module)\n        else:\n            module = importlib.import_module(module_path)\n    return module\n\n\ndef split_module_path(module_path: str) -> Tuple[str, str]:\n    \"\"\"\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/mod.py#L15-L51","documentation":"qlib.utils.mod.get_module_by_module_path loads a module from a filesystem path (.py), a dotted module path, or a ModuleType. Passing None is treated as a programming/configuration mistake and raises ModuleNotFoundError immediately rather than failing obscurely inside importlib. Note: this is raised via raise, so it propagates even though ModuleNotFoundError normally signals a missing package.","triggerScenarios":"init_instance_by_config({'class': 'MyHandler', 'module_path': None}) or get_callable_kwargs where a config dict's 'module_path' key exists but its value is None; dynamically built configs where a template left module_path unset.","commonSituations":"YAML/JSON workflow configs (e.g. qlib task or workflow configs) with an explicit `module_path: null`; code that reads module_path with config.get('module_path') instead of omitting the key; conditional config assembly that assigns None on a missing branch.","solutions":["Remove the module_path key entirely (qlib then falls back to default_module) or set it to a real dotted path / .py file path.","In config-building code, use config.pop('module_path', None) only when the value is truthy, or filter out None values before calling init_instance_by_config.","If a string class name is used, put the full path 'a.b.c.ClassName' in the config string so split_module_path handles it."],"exampleFix":"// before\nconf = {'class': 'TopkDropoutStrategy', 'module_path': None}\ninst = init_instance_by_config(conf)\n\n// after\nconf = {'class': 'TopkDropoutStrategy', 'module_path': 'qlib.contrib.strategy'}\ninst = init_instance_by_config(conf)","handlingStrategy":"validation","validationCode":"conf = {k: v for k, v in conf.items() if v is not None}  # drop null module_path\ninst = init_instance_by_config(conf)","typeGuard":"def is_valid_module_path(mp) -> bool:\n    return mp is None is False and (isinstance(mp, str) and len(mp) > 0)","tryCatchPattern":"try:\n    inst = init_instance_by_config(conf)\nexcept ModuleNotFoundError as e:\n    if 'None is passed' in str(e):\n        conf.pop('module_path', None)\n        inst = init_instance_by_config(conf)\n    else:\n        raise","preventionTips":["Never write `module_path: null` in workflow YAML — omit the key to use the default module.","Sanitize configs by filtering None values before init_instance_by_config."],"tags":["qlib","config","module-import","modulenotfounderror","init-instance"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}