dabla commented on code in PR #77377:
URL: https://github.com/apache/airflow/pull/77377#discussion_r4640966765


##########
providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py:
##########
@@ -35,7 +35,7 @@
 
 @pytest.fixture
 def mocked_blob_file_system():
-    with mock.patch("adlfs.AzureBlobFileSystem") as m:
+    with mock.patch("adlfs.AzureBlobFileSystem", autospec=True) as m:

Review Comment:
   **[warning]** `autospec=True` does not make the tests catch a keyword adlfs 
ignores, which is the cause of #77371.
   
   `AzureBlobFileSystem.__init__` ends in `**kwargs` 
([spec.py#L308-L324](https://github.com/fsspec/adlfs/blob/2026.8.0/adlfs/spec.py#L308-L324)),
 so the autospecced mock still accepts `account_url=...` without complaint 
(checked: `mock.patch("adlfs.AzureBlobFileSystem", autospec=True)` followed by 
`m(account_url="https://x";)` passes). The tests only prove which keywords 
`get_fs()` sends, not that adlfs uses them, and that is how the bug went 
unnoticed.
   
   The issue asks for a test that uses the real constructor. Building it needs 
no network: for the shared-key and full-URL connections, call `get_fs()` 
without the mock and assert `fs.account_name` and `fs.account_url`.



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py:
##########
@@ -77,8 +77,14 @@ def get_fs(conn_id: str | None, storage_options: dict[str, 
Any] | None = None) -
         # is the storage account name rather than part of an account URL.
         options["account_name"] = account_name
     elif conn_type != "adls" or conn.host or not tenant_id:
-        # WASB, full-URL, and custom-endpoint connections keep the historical 
account_url path.
-        options["account_url"] = parse_blob_account_url(conn.host, conn.login)
+        # WASB, full-URL, and custom-endpoint connections: derive the account 
name (and a
+        # non-default host) from the account URL instead of passing 
``account_url`` itself,
+        # which adlfs ignores.
+        account_url = urlparse(parse_blob_account_url(conn.host, conn.login))
+        account_name = account_url.netloc.split(".")[0]

Review Comment:
   **[blocker]** The account name is now derived from `login` even when `login` 
is a service principal client id or is empty, and that breaks connections that 
work on main.
   
   `parse_blob_account_url(conn.host, conn.login)` falls back to 
`https://{login}.blob.core.windows.net/` when there is no host or the host has 
no dot 
([utils.py#L194-L208](https://github.com/apache/airflow/blob/ed35c140e77d0d8167cb336b8afa527dde07cb4a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/utils.py#L194-L208)).
 For a `wasb` connection with `tenant_id` set, `login` is the client id, so 
this line produces an account name out of a truncated GUID. With no login at 
all it produces the string `"None"`.
   
   On main the `account_url` keyword was ignored by adlfs, so these connections 
took the account from `AZURE_STORAGE_ACCOUNT_NAME`. adlfs reads that variable 
only when no `account_name` is passed 
([spec.py#L335](https://github.com/fsspec/adlfs/blob/2026.8.0/adlfs/spec.py#L335)),
 so the derived value now hides it. Built against the real 
`AzureBlobFileSystem` with `AZURE_STORAGE_ACCOUNT_NAME=envacct`:
   
   | Connection | main | this PR |
   | --- | --- | --- |
   | `wasb`, login = client id, `tenant_id` in Extra, no host | 
`https://envacct.blob.core.windows.net` | 
`https://11111111-2222-3333-4444-.blob.core.windows.net` |
   | same, with an Active Directory id in Host | 
`https://envacct.blob.core.windows.net` | 
`https://11111111-2222-3333-4444-.blob.core.windows.net` |
   | `wasb`, no login, no host, `sas_token` in Extra | 
`https://envacct.blob.core.windows.net` | `https://None.blob.core.windows.net` |
   
   Without the env var these cases used to fail with a clear `ValueError`; they 
now build a filesystem for an account that does not exist and fail later on DNS.
   
   Derive the name only when the URL really identifies the account: the host is 
an endpoint (has a dot), or there is a login and no `tenant_id`. Otherwise set 
nothing, as the comment below this branch already describes for `adls`. Please 
add these three shapes as test cases.



##########
providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py:
##########
@@ -273,3 +272,79 @@ def test_get_fs(mocked_connection, expected_options, 
mocked_blob_file_system):
 )
 def test_bare_account_name_from_host(host, expected):
     assert _bare_account_name_from_host(host) == expected
+
+
[email protected](
+    ("mocked_connection", "storage_options", "expected_options"),
+    [
+        pytest.param(
+            Connection(
+                conn_id="testconn",
+                conn_type="wasb",
+                login="testaccountname",
+                password="password",
+            ),
+            None,
+            {"account_name": "testaccountname", "account_key": "password"},
+            id="wasb-account-key",
+        ),
+        pytest.param(
+            Connection(
+                conn_id="testconn",
+                conn_type="azure_data_lake",
+                host="https://testaccountname.blob.core.windows.net/";,
+                password="password",
+            ),
+            None,
+            {"account_name": "testaccountname", "account_key": "password"},
+            id="full-url-host",
+        ),
+        pytest.param(
+            Connection(
+                conn_id="testconn",
+                conn_type="azure_data_lake",
+                host="https://testaccountname.blob.core.mydomain.io/";,
+                password="password",
+            ),
+            None,
+            {
+                "account_name": "testaccountname",
+                "account_host": "testaccountname.blob.core.mydomain.io",
+                "account_key": "password",
+            },
+            id="full-url-custom-host",
+        ),
+        pytest.param(
+            Connection(
+                conn_id="testconn",
+                conn_type="wasb",
+                host="https://testaccountname.blob.core.mydomain.io/";,
+                password="password",
+                extra={
+                    "account_name": "extraaccount",
+                    "account_key": "extra_key",
+                    "account_host": "extraaccount.blob.core.mydomain.io",
+                },
+            ),
+            {
+                "account_name": "overrideaccount",
+                "account_key": "override_key",
+                "account_host": "overrideaccount.blob.core.mydomain.io",
+            },
+            {
+                "account_name": "overrideaccount",
+                "account_key": "override_key",
+                "account_host": "overrideaccount.blob.core.mydomain.io",
+            },
+            id="storage-options-override",
+        ),
+    ],
+    indirect=["mocked_connection"],
+)
[email protected]("adlfs.AzureBlobFileSystem", autospec=True)
+def test_get_fs_account_information(

Review Comment:
   **[warning]** `test_get_fs_account_information` repeats `test_get_fs` 
instead of extending it.
   
   It has the same body (call `get_fs`, assert the constructor keywords), 
patches `adlfs.AzureBlobFileSystem` a second time with a decorator although the 
`mocked_blob_file_system` fixture does exactly that, and its `wasb-account-key` 
case is the existing `test_get_fs` case with `login` and `password` under 
another name. Give `test_get_fs` a `storage_options` parameter (default `None`) 
and add the new shapes there, so there is one table of connection shapes to 
keep up to date.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to