mlflow/mlflow · error · MlflowException
RESOURCE_ALREADY_EXISTS
RESOURCE_ALREADY_EXISTS
Error message
User (username={username}) already exists. Error: {e} What it means
create_user inserts a SqlUser and lets the database enforce username uniqueness via a unique constraint; on an IntegrityError (duplicate username), it re-raises as MlflowException with RESOURCE_ALREADY_EXISTS. This is the standard pre-check-free pattern relying on DB constraints.
Source
Thrown at mlflow/server/auth/sqlalchemy_store.py:157
with self.ManagedSessionMaker() as session:
try:
user = self._get_user(session, username)
return check_password_hash(user.password_hash, password)
except MlflowException:
return False
def create_user(self, username: str, password: str, is_admin: bool = False) -> User:
_validate_username(username)
_validate_password(password)
pwhash = generate_password_hash(password)
with self.ManagedSessionMaker(read_only=False) as session:
try:
user = SqlUser(username=username, password_hash=pwhash, is_admin=is_admin)
session.add(user)
session.flush()
return user.to_mlflow_entity()
except IntegrityError as e:
raise MlflowException(
f"User (username={username}) already exists. Error: {e}",
RESOURCE_ALREADY_EXISTS,
) from e
@staticmethod
def _get_user(session, username: str) -> SqlUser:
try:
return session.query(SqlUser).filter(SqlUser.username == username).one()
except NoResultFound:
raise MlflowException(
f"User with username={username} not found",
RESOURCE_DOES_NOT_EXIST,
)
except MultipleResultsFound:
raise MlflowException(
f"Found multiple users with username={username}",
INVALID_STATE,
)View on GitHub (pinned to 6a27f2decc)
Solutions
- Use a different username, or query the existing user via get_user/auth APIs and update instead of create
- Catch MlflowException with code RESOURCE_ALREADY_EXISTS and treat it as idempotent in bootstrap scripts
- Check for the user's existence before calling create_user
Example fix
// before
store.create_user("admin@example.com", password, True)
// after
try:
store.create_user("admin@example.com", password, True)
except MlflowException as e:
if e.get_http_status_code() != 409:
raise Defensive patterns
Strategy: try-catch
Validate before calling
existing = store.get_user(username)
if existing:
user = existing
else:
user = store.create_user(username, password, is_admin) Try / catch
from mlflow.exceptions import MlflowException, RESOURCE_ALREADY_EXISTS
try:
user = store.create_user(username, password, is_admin)
except MlflowException as e:
if e.get_http_status_code() == 409 or RESOURCE_ALREADY_EXISTS in str(e.code):
user = store.get_user(username)
else:
raise Prevention
- Make user-creation bootstrap scripts idempotent (check-then-create or catch 409)
- Run bootstrap only once per database
- Uniquely prefix usernames in test environments to avoid collisions
When it happens
Trigger: Calling create_user (or the REST /api/2.0/mlflow/users/create endpoint, or the initial admin-creation bootstrap) with a username that already exists in the users table.
Common situations: Re-running auth bootstrap scripts (e.g. MLFLOW_AUTH_CONFIG_PATH init creating the default admin) against an already-initialized DB; concurrent user creation; duplicate signup attempts.
Related errors
- RESOURCE_ALREADY_EXISTS
- Could not find Databricks configuration file (${basePath}).
- Could not find 'DEFAULT' section within config file (${baseP
- Could not find '${profile}' section within config file (${b
- No 'host' configured within Databricks config file (${basePa
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/09e3ffce0a78c364.
Report an issue: GitHub.