microsoft/qlib · error · AttributeError

No such `{attr}` in self._config

Error message

No such `{attr}` in self._config

What it means

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.

Source

Thrown at qlib/config.py:93

        if not self.get("provider_uri"):
            errors.append("provider_uri must be set (e.g. ~/.qlib/qlib_data or a valid path)")

        if not self.get("region"):
            errors.append("region must be specified (e.g. 'cn', 'us')")

        if errors:
            raise ValueError(
                "Invalid Qlib configuration (note: the global config has already been updated):\n"
                "Invalid Qlib configuration:\n- " + "\n- ".join(errors)
            )

    def __getitem__(self, key):
        return self.__dict__["_config"][key]

    def __getattr__(self, attr):
        if attr in self.__dict__["_config"]:
            return self.__dict__["_config"][attr]
        raise AttributeError(f"No such `{attr}` in self._config")

    def get(self, key, default=None):
        return self.__dict__["_config"].get(key, default)

    def __setitem__(self, key, value):
        self.__dict__["_config"][key] = value

    def __setattr__(self, attr, value):
        self.__dict__["_config"][attr] = value

    def __contains__(self, item):
        return item in self.__dict__["_config"]

    def __getstate__(self):
        return self.__dict__

    def __setstate__(self, state):
        self.__dict__.update(state)

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use dict-style access with a default: qlib.config.get('your_key', default) instead of attribute access.
  2. Ensure qlib.init(...) ran in the process and passed the key you later read (extra kwargs to init land in the global config).
  3. Check exact key spelling/case against what was passed to init; print qlib.config._config keys to see what is actually set.

Example fix

# before
val = qlib.config.my_custom_key  # AttributeError if unset
# after
val = qlib.config.get('my_custom_key', None)  # explicit default
Defensive patterns

Strategy: type-guard

Validate before calling

value = qlib.config.get('your_key')
if value is None:
    raise KeyError('your_key not set; call qlib.init(...) with it first')

Type guard

def has_config_key(key: str) -> bool:
    return key in qlib.config  # QlibConfig implements __contains__

Try / catch

try:
    v = qlib.config.your_key
except AttributeError:
    v = DEFAULT_VALUE

Prevention

When it happens

Trigger: 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).

Common situations: Library code that reads optional config keys directly instead of .get(); running utility modules standalone without init; key renamed across qlib versions.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/00d6fcbf9781c7a3. Report an issue: GitHub.