{"record":{"id":"001df4cbe5a8a6d3","repo":"mlflow/mlflow","slug":"resource-already-exists-001df4","errorCode":"RESOURCE_ALREADY_EXISTS","errorMessage":"Secret with name '{secret_name}' already exists","messagePattern":"Secret with name '(.+?)' already exists","errorType":"error_code","errorClass":"MlflowException","httpStatus":409,"severity":"error","filePath":"mlflow/store/tracking/gateway/sqlalchemy_mixin.py","lineNumber":256,"sourceCode":"                    secret_name=secret_name,\n                    encrypted_value=encrypted.encrypted_value,\n                    wrapped_dek=encrypted.wrapped_dek,\n                    masked_value=json.dumps(masked_value),\n                    kek_version=encrypted.kek_version,\n                    provider=provider,\n                    auth_config=json.dumps(auth_config) if auth_config else None,\n                    created_at=current_time,\n                    last_updated_at=current_time,\n                    created_by=created_by,\n                    last_updated_by=created_by,\n                )\n            )\n\n            try:\n                session.add(sql_secret)\n                session.flush()\n            except IntegrityError as e:\n                raise MlflowException(\n                    f\"Secret with name '{secret_name}' already exists\",\n                    error_code=RESOURCE_ALREADY_EXISTS,\n                ) from e\n\n            return sql_secret.to_mlflow_entity()\n\n    def get_secret_info(\n        self, secret_id: str | None = None, secret_name: str | None = None\n    ) -> GatewaySecretInfo:\n        \"\"\"\n        Retrieve secret metadata by ID or name (does not decrypt the value and only\n        returns the masked secret for the purposes of key identification for users).\n\n        Args:\n            secret_id: ID of the secret to retrieve.\n            secret_name: Name of the secret to retrieve.\n\n        Returns:","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/store/tracking/gateway/sqlalchemy_mixin.py#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check whether the secret already exists (list/get gateway secrets by name) and reuse it instead of creating a new one.","Use a different, unique secret name.","If overwrite is intended, update the existing secret's value rather than creating a duplicate.","Handle the RESOURCE_ALREADY_EXISTS error code and treat the secret as already provisioned."],"exampleFix":"// before\nclient.create_gateway_secret(\"openai-api-key\", \"sk-...\")  # fails on rerun\n// after\nif not any(s.name == \"openai-api-key\" for s in client.search_gateway_secrets()):\n    client.create_gateway_secret(\"openai-api-key\", \"sk-...\")","handlingStrategy":"try-catch","validationCode":"existing = [s for s in client.search_gateway_secrets() if s.name == secret_name]\nif existing:\n    return existing[0]","typeGuard":"null","tryCatchPattern":"try:\n    client.create_gateway_secret(secret_name, value)\nexcept MlflowException as e:\n    if e.error_code == \"RESOURCE_ALREADY_EXISTS\":\n        return  # secret already provisioned\n    raise","preventionTips":["Check for an existing secret by name before creating","Make provisioning scripts idempotent by catching RESOURCE_ALREADY_EXISTS","Use per-environment secret name prefixes to avoid collisions"],"tags":["mlflow","gateway","secrets","database","duplicate-resource"],"backgroundTag":"duplicate-resource-conflict","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}