{"record":{"id":"8f0346538c1aabde","repo":"microsoft/qlib","slug":"cannot-find-user-8f0346","errorCode":null,"errorMessage":"Cannot find user ","messagePattern":"Cannot find user ","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/operator.py","lineNumber":299,"sourceCode":"        um.save_user_data(id)\r\n        self.show(id, path, bench)\r\n\r\n    def show(self, id, path, bench=\"SH000905\"):\r\n        \"\"\"show the newly report (mean, std, information_ratio, annualized_return)\r\n\r\n        Parameters\r\n        ----------\r\n        id : str\r\n            user id, need to be unique\r\n        path : str\r\n            Path to save user account.\r\n        bench : str\r\n            The benchmark that our result compared with.\r\n            'SH000905' for csi500, 'SH000300' for csi300\r\n        \"\"\"\r\n        um = self.init(self.client, path, None)[0]\r\n        if id not in um.users:\r\n            raise ValueError(\"Cannot find user \".format(id))\r\n        bench = D.features([bench], [\"$change\"]).loc[bench, \"$change\"]\r\n        portfolio_metrics = um.users[id].account.portfolio_metrics.generate_portfolio_metrics_dataframe()\r\n        portfolio_metrics[\"bench\"] = bench\r\n        analysis_result = {}\r\n        r = (portfolio_metrics[\"return\"] - portfolio_metrics[\"bench\"]).dropna()\r\n        analysis_result[\"excess_return_without_cost\"] = risk_analysis(r)\r\n        r = (portfolio_metrics[\"return\"] - portfolio_metrics[\"bench\"] - portfolio_metrics[\"cost\"]).dropna()\r\n        analysis_result[\"excess_return_with_cost\"] = risk_analysis(r)\r\n        print(\"Result:\")\r\n        print(\"excess_return_without_cost:\")\r\n        print(analysis_result[\"excess_return_without_cost\"])\r\n        print(\"excess_return_with_cost:\")\r\n        print(analysis_result[\"excess_return_with_cost\"])\r\n\r\n\r\ndef run():\r\n    fire.Fire(Operator)\r\n\r","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/operator.py#L281-L317","documentation":"Raised by OnlineOperator.check_user (operator.py:299) when the requested id is not in the loaded UserManager's users dict. The report/risk-analysis step needs the user's portfolio_metrics, so the user must exist and be loaded first. Note the message has a formatting bug — the string has no {} placeholder, so .format(id) is a no-op and the id never appears in the error text.","triggerScenarios":"Calling op.check_user(id=..., ...) with a typo'd id, before um.load_users() has run (init does load via UserManager in operator.init), or for a user whose data folder exists but is not recorded in users_file.","commonSituations":"Reports requested for a user id with different casing/format; users_file CSV out of sync with the folders on disk; calling check_user right after manually copying a user folder without registering it.","solutions":["List loaded users first: um = op.init(client, path, None)[0]; print(list(um.users)) and use an exact id from it.","Ensure the user was added via add_user / registered in users_file before reporting on it.","If the CSV is out of sync, re-register the user or fix users_file so load_users picks it up."],"exampleFix":"# before\nop.check_user(id=\"u_9\", path=p, bench=\"SH000300\")  # ValueError: Cannot find user\n\n# after\num = op.init(op.client, p, None)[0]\nprint(list(um.users))              # discover exact id, e.g. 'u09'\nop.check_user(id=\"u09\", path=p, bench=\"SH000300\")","handlingStrategy":"validation","validationCode":"um = op.init(op.client, path, None)[0]\nif id not in um.users:\n    raise KeyError(f\"unknown user id {id!r}; loaded users: {sorted(um.users)}\")\nop.check_user(id=id, path=path, bench=\"SH000300\")","typeGuard":"def user_exists(um, user_id) -> bool:\n    return user_id in um.users","tryCatchPattern":null,"preventionTips":["Discover ids from list(um.users) instead of hard-coding guesses.","Register users via add_user so users_file stays authoritative.","Note the error message omits the id (formatting bug in qlib) — log your own id."],"tags":["qlib","online-operator","user","file-not-found","reporting"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}