mlflow/mlflow · error · MlflowException

RESOURCE_ALREADY_EXISTS

RESOURCE_ALREADY_EXISTS

Error message

Secret with name '{secret_name}' already exists

What it means

MLflow's gateway tracking store raises this when inserting a new gateway secret whose name already violates the unique constraint in the secrets table. The INSERT fails with a database IntegrityError, which is converted into an MlflowException with error code RESOURCE_ALREADY_EXISTS. It signals the caller is trying to create a secret that already exists rather than overwrite it.

Source

Thrown at mlflow/store/tracking/gateway/sqlalchemy_mixin.py:256

                    secret_name=secret_name,
                    encrypted_value=encrypted.encrypted_value,
                    wrapped_dek=encrypted.wrapped_dek,
                    masked_value=json.dumps(masked_value),
                    kek_version=encrypted.kek_version,
                    provider=provider,
                    auth_config=json.dumps(auth_config) if auth_config else None,
                    created_at=current_time,
                    last_updated_at=current_time,
                    created_by=created_by,
                    last_updated_by=created_by,
                )
            )

            try:
                session.add(sql_secret)
                session.flush()
            except IntegrityError as e:
                raise MlflowException(
                    f"Secret with name '{secret_name}' already exists",
                    error_code=RESOURCE_ALREADY_EXISTS,
                ) from e

            return sql_secret.to_mlflow_entity()

    def get_secret_info(
        self, secret_id: str | None = None, secret_name: str | None = None
    ) -> GatewaySecretInfo:
        """
        Retrieve secret metadata by ID or name (does not decrypt the value and only
        returns the masked secret for the purposes of key identification for users).

        Args:
            secret_id: ID of the secret to retrieve.
            secret_name: Name of the secret to retrieve.

        Returns:

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Check whether the secret already exists (list/get gateway secrets by name) and reuse it instead of creating a new one.
  2. Use a different, unique secret name.
  3. If overwrite is intended, update the existing secret's value rather than creating a duplicate.
  4. Handle the RESOURCE_ALREADY_EXISTS error code and treat the secret as already provisioned.

Example fix

// before
client.create_gateway_secret("openai-api-key", "sk-...")  # fails on rerun
// after
if not any(s.name == "openai-api-key" for s in client.search_gateway_secrets()):
    client.create_gateway_secret("openai-api-key", "sk-...")
Defensive patterns

Strategy: try-catch

Validate before calling

existing = [s for s in client.search_gateway_secrets() if s.name == secret_name]
if existing:
    return existing[0]

Type guard

null

Try / catch

try:
    client.create_gateway_secret(secret_name, value)
except MlflowException as e:
    if e.error_code == "RESOURCE_ALREADY_EXISTS":
        return  # secret already provisioned
    raise

Prevention

When it happens

Trigger: Calling create_gateway_secret (or a client wrapper like MlflowClient.create_gateway_secret) with a secret_name that is already registered in the tracking database.

Common situations: Rerunning an idempotent bootstrap/setup script that provisions gateway secrets; concurrent workers both creating the same named secret; typo causing a name collision with an existing secret.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/001df4cbe5a8a6d3. Report an issue: GitHub.