{"record":{"id":"c95b9425b4f451df","repo":"pola-rs/polars","slug":"invalid-config-string-did-you-mean-to-use-load-f","errorCode":null,"errorMessage":"invalid Config string (did you mean to use `load_from_file`?)","messagePattern":"invalid Config string \\(did you mean to use `load_from_file`\\?\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":408,"sourceCode":"    def load(cls, cfg: str) -> Config:\n        \"\"\"\n        Load (and set) previously saved Config options from a JSON string.\n\n        Parameters\n        ----------\n        cfg : str\n            JSON string produced by `Config.save()`.\n\n        See Also\n        --------\n        load_from_file : Load (and set) Config options from a JSON file.\n        save : Save the current set of Config options as a JSON string or file.\n        \"\"\"\n        try:\n            options = json.loads(cfg)\n        except json.JSONDecodeError as err:\n            msg = \"invalid Config string (did you mean to use `load_from_file`?)\"\n            raise ValueError(msg) from err\n\n        cfg_load = Config()\n        opts = options.get(\"environment\", {})\n        if \"POLARS_ENGINE_AFFINITY\" in opts:\n            # A saved affinity value replaces any object affinity.\n            set_engine_affinity_override(None)\n        for key, opt in opts.items():\n            if opt is None:\n                os.environ.pop(key, None)\n            else:\n                os.environ[key] = opt\n\n        for cfg_methodname, value in options.get(\"direct\", {}).items():\n            if hasattr(cfg_load, cfg_methodname):\n                getattr(cfg_load, cfg_methodname)(value)\n\n        plr.config_reload_env_vars()\n        return cfg_load","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L390-L426","documentation":"`pl.Config.load(cfg)` expects a JSON *string* produced by `Config.save()` and immediately runs `json.loads` on it. If the input is not valid JSON — most commonly because a file path was passed instead of the file's contents — polars raises ValueError with a hint pointing you to `load_from_file`, the path-based variant.","triggerScenarios":"`pl.Config.load('polars_config.json')` (a path, not JSON); a truncated or hand-edited save string with syntax errors; passing an empty string.","commonSituations":"Confusing `load` (string) with `load_from_file` (path); hand-editing a saved config and breaking the JSON; storing the save string in a database and retrieving it truncated.","solutions":["For a file path, use `pl.Config.load_from_file('polars_config.json')`.","For a string, pass the exact output of `pl.Config.save()` or `Path('polars_config.json').read_text()`.","Validate hand-edited strings with `json.loads` first and fix any syntax errors it reports."],"exampleFix":"# before\npl.Config.load(\"polars_config.json\")  # it's a path -> invalid Config string\n\n# after\npl.Config.load_from_file(\"polars_config.json\")","handlingStrategy":"validation","validationCode":"import json\n\ndef load_config(cfg: str) -> None:\n    if not cfg.lstrip().startswith(\"{\"):\n        raise ValueError(\"cfg does not look like JSON — for a file path use pl.Config.load_from_file(cfg)\")\n    json.loads(cfg)  # fail fast with a precise JSON error\n    pl.Config.load(cfg)","typeGuard":null,"tryCatchPattern":"try:\n    pl.Config.load(cfg)\nexcept ValueError as err:\n    if \"did you mean to use `load_from_file`\" in str(err):\n        pl.Config.load_from_file(cfg)  # it was a path after all\n    else:\n        raise","preventionTips":["Convention: strings from Config.save() go to load(), filesystem paths go to load_from_file().","Validate config strings with json.loads before loading them in tests.","Store saved config in one place and load it through a single helper to avoid mixing APIs."],"tags":["config","json","load","polars"],"backgroundTag":"invalid-json-config","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}