diff --git a/storages/backends/azure_storage.py b/storages/backends/azure_storage.py index df27994c6..7d89e2426 100644 --- a/storages/backends/azure_storage.py +++ b/storages/backends/azure_storage.py @@ -184,6 +184,11 @@ def _get_service_client(self): DeprecationWarning, ) options["api_version"] = self.api_version + + # allow account url override for very custom azure instances/routing + if "account_url" in options: + return BlobServiceClient(credential=credential, **options) + return BlobServiceClient(account_url, credential=credential, **options) @property diff --git a/tests/test_azure.py b/tests/test_azure.py index 059cb2eec..7cb1b52dc 100644 --- a/tests/test_azure.py +++ b/tests/test_azure.py @@ -293,6 +293,18 @@ def test_container_client_params_token_credential(self): "https://test.blob.core.windows.net", credential="foo_cred" ) + def test_container_client_params_token_credential_and_super_custom_url(self): + storage = azure_storage.AzureStorage() + storage.token_credential = "foo_cred" + storage.client_options = {"account_url": "https://bar.com"} + with mock.patch( + "storages.backends.azure_storage.BlobServiceClient", autospec=True + ) as bsc_mocked: + client_mock = mock.MagicMock() + bsc_mocked.return_value.get_container_client.return_value = client_mock + self.assertEqual(storage.client, client_mock) + bsc_mocked.assert_called_once_with("https://bar.com", credential="foo_cred") + def test_connection_string_can_have_missing(self): storage = azure_storage.AzureStorage( connection_string="AccountKey=abc;Foobar=xyz;"