{"record":{"id":"7c2e3fca346ef593","repo":"mem0ai/mem0","slug":"azure-identity-is-required-for-azure-credential-au","errorCode":null,"errorMessage":"Azure Identity is required for Azure credential authentication. Please install it using 'pip install azure-identity'","messagePattern":"Azure Identity is required for Azure credential authentication\\. Please install it using 'pip install azure-identity'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"mem0/vector_stores/azure_mysql.py","lineNumber":101,"sourceCode":"            maxconn (int): Maximum number of connections in the pool\n            connection_pool (Any, optional): Pre-configured connection pool\n        \"\"\"\n        self.host = host\n        self.port = port\n        self.user = user\n        self.password = password\n        self.database = database\n        self.collection_name = _validate_identifier(collection_name, \"collection_name\")\n        self.embedding_model_dims = embedding_model_dims\n        self.use_azure_credential = use_azure_credential\n        self.ssl_ca = ssl_ca\n        self.ssl_disabled = ssl_disabled\n        self.connection_pool = connection_pool\n\n        # Handle Azure authentication\n        if use_azure_credential:\n            if not AZURE_IDENTITY_AVAILABLE:\n                raise ImportError(\n                    \"Azure Identity is required for Azure credential authentication. \"\n                    \"Please install it using 'pip install azure-identity'\"\n                )\n            self._setup_azure_auth()\n\n        # Setup connection pool\n        if self.connection_pool is None:\n            self._setup_connection_pool(minconn, maxconn)\n\n        # Create collection if it doesn't exist\n        collections = self.list_cols()\n        if collection_name not in collections:\n            self.create_col(name=collection_name, vector_size=embedding_model_dims, distance=\"cosine\")\n\n    def _setup_azure_auth(self):\n        \"\"\"Setup Azure authentication using DefaultAzureCredential.\"\"\"\n        try:\n            credential = DefaultAzureCredential()","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/azure_mysql.py#L83-L119","documentation":"Raised by AzureMySQL.__init__ when use_azure_credential=True but the optional 'azure-identity' package is not installed. The module probes for it at import time (mem0/vector_stores/azure_mysql.py:19-23) and sets AZURE_IDENTITY_AVAILABLE=False on ImportError; the constructor then refuses to proceed because _setup_azure_auth() needs DefaultAzureCredential to fetch a token for Azure Database for MySQL.","triggerScenarios":"Instantiating AzureMySQL (directly or via VectorStoreConfig with provider 'azure_mysql') with use_azure_credential=True in an environment where 'pip install azure-identity' was never run. PyMySQL/DBUtils are installed (they are hard imports at the top of the file), so the failure only appears at construction time, not import time.","commonSituations":"Deploying to a container or CI image built from core mem0ai extras without the Azure extras; copying a config that worked on a dev machine with azure-identity already present; switching from password auth to managed-identity auth on Azure App Service/Container Apps where the library was not bundled.","solutions":["Install the package: pip install azure-identity (or add it to your requirements.txt / image).","If you do not want Azure AD auth, set use_azure_credential back to False and authenticate with the password argument instead.","Add an environment check to your Dockerfile/CI: python -c \"import azure.identity\" to fail builds early rather than at runtime."],"exampleFix":"# before\nAzureMySQL(host=..., use_azure_credential=True)  # ImportError\n\n# after (option 1)\n# pip install azure-identity\nAzureMySQL(host=..., use_azure_credential=True)\n\n# after (option 2)\nAzureMySQL(host=..., password=os.environ['MYSQL_PWD'], use_azure_credential=False)","handlingStrategy":"validation","validationCode":"def can_use_azure_credential() -> bool:\n    try:\n        import azure.identity  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nassert can_use_azure_credential(), \"pip install azure-identity before enabling use_azure_credential\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add azure-identity to the same requirements set as the azure_mysql provider config.","Run python -c \"import azure.identity\" in CI for services that use Azure AD auth.","Fail fast at startup on the capability check instead of at first vector-store construction."],"tags":["azure","mysql","dependencies","import-error","auth"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}