{"record":{"id":"ea13532b8d0cb605","repo":"microsoft/qlib","slug":"cannot-find-user","errorCode":null,"errorMessage":"Cannot find user {}","messagePattern":"Cannot find user (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/manager.py","lineNumber":84,"sourceCode":"        cur_user_list = list(self.users)\n        if user_id in cur_user_list:\n            raise ValueError(\"User {} has been loaded\".format(user_id))\n        else:\n            trade_account = Account(0)\n            trade_account.load_account(account_path)\n            strategy = load_instance(strategy_file)\n            model = load_instance(model_file)\n            user = User(account=trade_account, strategy=strategy, model=model)\n            return user\n\n    def save_user_data(self, user_id):\n        \"\"\"\n        save a instance of User() to user data path\n            Parameter\n                user_id : string\n        \"\"\"\n        if not user_id in self.users:\n            raise ValueError(\"Cannot find user {}\".format(user_id))\n        self.users[user_id].account.save_account(self.data_path / user_id)\n        save_instance(\n            self.users[user_id].strategy,\n            self.data_path / user_id / \"strategy_{}.pickle\".format(user_id),\n        )\n        save_instance(\n            self.users[user_id].model,\n            self.data_path / user_id / \"model_{}.pickle\".format(user_id),\n        )\n\n    def add_user(self, user_id, config_file, add_date):\n        \"\"\"\n        add the new user {user_id} into user data\n        will create a new folder named \"{user_id}\" in user data path\n            Parameter\n                user_id : string\n                init_cash : int\n                config_file : str/pathlib.Path()","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/manager.py#L66-L102","documentation":"Raised by UserManager.save_user_data when the given user_id is not a key in the in-memory self.users dict. Saving serializes the user's account, strategy and model pickles, so it requires the user to have been loaded/created in this UserManager instance first.","triggerScenarios":"Calling save_user_data(user_id) before load_users() or before create_user added that id; passing a typo'd or removed user_id; calling save on a fresh UserManager constructed with a data_path but never populated.","commonSituations":"Scripts that assume users are auto-discovered from disk without calling load_users(); user was removed earlier in the session and then saved; case/format mismatch of the id string (e.g. '01' vs '1').","solutions":["Call um.load_users() after constructing UserManager so existing users are in um.users.","Verify the id: assert user_id in um.users before save_user_data(user_id).","If the user is new, create it first with create_user/add_user before saving."],"exampleFix":"# before\num = UserManager(user_data_path=p)\num.save_user_data(\"u1\")  # ValueError: Cannot find user u1\n\n# after\num = UserManager(user_data_path=p)\num.load_users()               # populate um.users from disk\nif \"u1\" in um.users:\n    um.save_user_data(\"u1\")","handlingStrategy":"validation","validationCode":"um.load_users()\nassert user_id in um.users, f\"user {user_id} not loaded; check users_file and folders\"\num.save_user_data(user_id)","typeGuard":"def can_save_user(um, user_id) -> bool:\n    return user_id in um.users","tryCatchPattern":null,"preventionTips":["Always call load_users() right after constructing UserManager.","Assert the id exists before save/remove operations.","Normalize user id strings once at the system boundary to avoid format mismatches."],"tags":["qlib","online-manager","user","state","validation"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}