microsoft/qlib · error · ValueError
User {} has been loaded
Error message
User {} has been loaded What it means
Raised by UserManager.create_user (qlib/contrib/online/manager.py) when trying to load a user whose user_id is already present in the in-memory self.users dict. The manager refuses to load the same online-user twice to avoid duplicate accounts/strategies being tracked under one id.
Source
Thrown at qlib/contrib/online/manager.py:68
self.users = {}
self.user_record = pd.read_csv(self.users_file, index_col=0)
for user_id in self.user_record.index:
self.users[user_id] = self.load_user(user_id)
def load_user(self, user_id):
"""
return a instance of User() represents a user to be processed
Parameter
user_id : string
:return
user : User()
"""
account_path = self.data_path / user_id
strategy_file = self.data_path / user_id / "strategy_{}.pickle".format(user_id)
model_file = self.data_path / user_id / "model_{}.pickle".format(user_id)
cur_user_list = list(self.users)
if user_id in cur_user_list:
raise ValueError("User {} has been loaded".format(user_id))
else:
trade_account = Account(0)
trade_account.load_account(account_path)
strategy = load_instance(strategy_file)
model = load_instance(model_file)
user = User(account=trade_account, strategy=strategy, model=model)
return user
def save_user_data(self, user_id):
"""
save a instance of User() to user data path
Parameter
user_id : string
"""
if not user_id in self.users:
raise ValueError("Cannot find user {}".format(user_id))
self.users[user_id].account.save_account(self.data_path / user_id)
save_instance(View on GitHub (pinned to 79633dd950)
Solutions
- Skip creation if the user already exists: check `user_id in um.users` before calling create_user.
- Use a unique user_id for each new online user.
- If the existing entry is stale, call um.remove_user(user_id) (and reload) before creating it again.
Example fix
# before
um.load_users()
user = um.create_user("u1") # ValueError: User u1 has been loaded
# after
um.load_users()
if "u1" not in um.users:
user = um.create_user("u1") Defensive patterns
Strategy: validation
Validate before calling
if user_id in um.users:
user = um.users[user_id]
else:
user = um.create_user(user_id) Type guard
def user_loaded(um, user_id) -> bool:
return user_id in um.users Prevention
- Check membership in um.users before create_user.
- Generate unique user ids (uuid or strict counters).
- Keep load_users() and manual create_user calls in one coordinator function.
When it happens
Trigger: Calling um.load_users() (which loads all recorded users) and then um.create_user(user_id) for an id already in users_file; or calling create_user twice with the same user_id in one session.
Common situations: An online-serving script that both bulk-loads users and re-adds one explicitly; retrying a failed setup script without restarting the UserManager; id collisions because user ids are derived from timestamps or counters that repeat.
Related errors
- Cannot find user {}
- User data for {} already exists
- Cannot find user data {}
- model is not fitted yet!
- model is not fitted yet!
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/62a68ce6e2b73098.
Report an issue: GitHub.