{"record":{"id":"dde59f84abf0d4c6","repo":"microsoft/qlib","slug":"user-data-for-already-exists","errorCode":null,"errorMessage":"User data for {} already exists","messagePattern":"User data for (.+?) already exists","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/manager.py","lineNumber":110,"sourceCode":"            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()\n                   path of config file\n        \"\"\"\n        config_file = pathlib.Path(config_file)\n        if not config_file.exists():\n            raise ValueError(\"Cannot find config file {}\".format(config_file))\n        user_path = self.data_path / user_id\n        if user_path.exists():\n            raise ValueError(\"User data for {} already exists\".format(user_id))\n\n        with config_file.open(\"r\") as fp:\n            yaml = YAML(typ=\"safe\", pure=True)\n            config = yaml.load(fp)\n        # load model\n        model = init_instance_by_config(config[\"model\"])\n\n        # load strategy\n        strategy = init_instance_by_config(config[\"strategy\"])\n        init_args = strategy.get_init_args_from_model(model, add_date)\n        strategy.init(**init_args)\n\n        # init Account\n        trade_account = Account(init_cash=config[\"init_cash\"])\n\n        # save user\n        user_path.mkdir()\n        save_instance(model, self.data_path / user_id / \"model_{}.pickle\".format(user_id))","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/manager.py#L92-L128","documentation":"Raised by UserManager.add_user when the target folder data_path/user_id already exists. add_user creates a fresh account folder for a new online user and refuses to overwrite an existing user's data directory.","triggerScenarios":"Calling add_user with a user_id whose folder was created previously (active user, or leftover from a partially failed add); re-running an initialization script without cleaning the user data path.","commonSituations":"Re-running a bootstrap script after a crash midway through add_user left the folder behind; retrying user creation because the first attempt failed after folder creation; id reuse across test runs against the same data path.","solutions":["If the user is stale/leftover, remove it first with um.remove_user(user_id) (or delete the folder), then add_user again.","Pick a fresh unique user_id for the new user.","Guard before creating: if (um.data_path / user_id).exists(), skip or clean up."],"exampleFix":"# before\num.add_user(user_id=\"u1\", config_file=cfg, add_date=d)\n# ValueError: User data for u1 already exists\n\n# after\nif (um.data_path / \"u1\").exists():\n    um.remove_user(\"u1\")  # or choose a new unique id\num.add_user(user_id=\"u1\", config_file=cfg, add_date=d)","handlingStrategy":"validation","validationCode":"user_path = um.data_path / user_id\nif user_path.exists():\n    um.remove_user(user_id)  # or pick a fresh unique id\num.add_user(user_id=user_id, config_file=cfg, add_date=add_date)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make user-creation scripts idempotent: existence check -> remove-or-skip -> add.","Use unique ids per run (timestamped) to avoid collisions.","Clean user data paths between test runs."],"tags":["qlib","online-manager","duplicate","user","filesystem"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}