{"record":{"id":"00d6fcbf9781c7a3","repo":"microsoft/qlib","slug":"no-such-attr-in-self-config","errorCode":null,"errorMessage":"No such `{attr}` in self._config","messagePattern":"No such `(.+?)` in self\\._config","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"qlib/config.py","lineNumber":93,"sourceCode":"        if not self.get(\"provider_uri\"):\n            errors.append(\"provider_uri must be set (e.g. ~/.qlib/qlib_data or a valid path)\")\n\n        if not self.get(\"region\"):\n            errors.append(\"region must be specified (e.g. 'cn', 'us')\")\n\n        if errors:\n            raise ValueError(\n                \"Invalid Qlib configuration (note: the global config has already been updated):\\n\"\n                \"Invalid Qlib configuration:\\n- \" + \"\\n- \".join(errors)\n            )\n\n    def __getitem__(self, key):\n        return self.__dict__[\"_config\"][key]\n\n    def __getattr__(self, attr):\n        if attr in self.__dict__[\"_config\"]:\n            return self.__dict__[\"_config\"][attr]\n        raise AttributeError(f\"No such `{attr}` in self._config\")\n\n    def get(self, key, default=None):\n        return self.__dict__[\"_config\"].get(key, default)\n\n    def __setitem__(self, key, value):\n        self.__dict__[\"_config\"][key] = value\n\n    def __setattr__(self, attr, value):\n        self.__dict__[\"_config\"][attr] = value\n\n    def __contains__(self, item):\n        return item in self.__dict__[\"_config\"]\n\n    def __getstate__(self):\n        return self.__dict__\n\n    def __setstate__(self, state):\n        self.__dict__.update(state)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/config.py#L75-L111","documentation":"qlib's QlibConfig routes attribute access through __getattr__ into its internal _config dict. If the attribute name is not a key in the dict (and not a real instance attribute), it raises AttributeError with 'No such `attr` in self._config'. This usually means either the config key was never set (qlib.init not called or not setting that key) or the key name is wrong.","triggerScenarios":"Accessing qlib.config.<key> for a key that is not in the global config — e.g. a custom key read before any qlib.init sets it, or reading 'custom_ops'/'kernels' style keys that only exist after specific init arguments; also typos like qlib.config.provider (should be provider_uri).","commonSituations":"Library code that reads optional config keys directly instead of .get(); running utility modules standalone without init; key renamed across qlib versions.","solutions":["Use dict-style access with a default: qlib.config.get('your_key', default) instead of attribute access.","Ensure qlib.init(...) ran in the process and passed the key you later read (extra kwargs to init land in the global config).","Check exact key spelling/case against what was passed to init; print qlib.config._config keys to see what is actually set."],"exampleFix":"# before\nval = qlib.config.my_custom_key  # AttributeError if unset\n# after\nval = qlib.config.get('my_custom_key', None)  # explicit default","handlingStrategy":"type-guard","validationCode":"value = qlib.config.get('your_key')\nif value is None:\n    raise KeyError('your_key not set; call qlib.init(...) with it first')","typeGuard":"def has_config_key(key: str) -> bool:\n    return key in qlib.config  # QlibConfig implements __contains__","tryCatchPattern":"try:\n    v = qlib.config.your_key\nexcept AttributeError:\n    v = DEFAULT_VALUE","preventionTips":["Prefer .get(key, default) or 'key' in qlib.config over attribute access for optional keys.","Set custom keys via qlib.init(**kwargs) at startup so later attribute reads succeed."],"tags":["qlib","config","attribute-error","init"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}