From 6a389088ef824633a4f22e471dc83a4ee3b4199d Mon Sep 17 00:00:00 2001 From: Lukas Hennies Date: Mon, 29 Sep 2025 12:59:50 +0200 Subject: [PATCH 1/3] feat: allow override for account_url --- storages/backends/azure_storage.py | 5 +++++ 1 file changed, 5 insertions(+) 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 From 2377106f4813df4b70b3177702f89669df72fe06 Mon Sep 17 00:00:00 2001 From: Lukas Hennies Date: Tue, 30 Sep 2025 11:23:03 +0200 Subject: [PATCH 2/3] test: account url override --- tests/test_azure.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_azure.py b/tests/test_azure.py index 059cb2eec..21d16b472 100644 --- a/tests/test_azure.py +++ b/tests/test_azure.py @@ -293,6 +293,20 @@ 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;" From 4297cff0b9100ba1d80c8ff519a3b76901932993 Mon Sep 17 00:00:00 2001 From: Lukas Hennies Date: Tue, 30 Sep 2025 11:31:05 +0200 Subject: [PATCH 3/3] chore: ruff --- tests/test_azure.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_azure.py b/tests/test_azure.py index 21d16b472..7cb1b52dc 100644 --- a/tests/test_azure.py +++ b/tests/test_azure.py @@ -303,9 +303,7 @@ def test_container_client_params_token_credential_and_super_custom_url(self): 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" - ) + bsc_mocked.assert_called_once_with("https://bar.com", credential="foo_cred") def test_connection_string_can_have_missing(self): storage = azure_storage.AzureStorage(