This is an automated email from the ASF dual-hosted git repository.

dabla pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new d3a0737c834 Fix ADLS ObjectStoragePath connection parsing (#68344)
d3a0737c834 is described below

commit d3a0737c8346d790e0b2714244316d71bb653ac7
Author: Chinmay Sawant <[email protected]>
AuthorDate: Fri Nov 20 04:17:53 2026 -0500

    Fix ADLS ObjectStoragePath connection parsing (#68344)
    
    * Fix ADLS ObjectStoragePath connection parsing
    
    * Tighten ADLS ObjectStoragePath parsing
    
    * Preserve ADLS account_url compatibility
    
    * Add newsfragment for ADLS ObjectStoragePath connection fix
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    
    * Address review feedback on ADLS host parsing
    
    - Collapse the two host helpers into one case-insensitive check. A
      mixed-case bare host like "MyAccount" was silently falling through to
      the account_url branch because urlparse lowercases the hostname; the
      new helper compares against host.lower() and keeps a dot guard so full
      endpoints (acct.dfs.core.windows.net) still use account_url. This also
      drops the unreachable split(".") branch the old pair carried.
    - Make the adls + no-host + tenant_id fall-through explicit with a
      comment; it's the one combination that sets neither key and leaves
      adlfs to use DefaultAzureCredential. Existing test already pins it.
    - Add a test for the mixed-case bare host.
    - Remove the newsfragment; providers regenerate the changelog from git
      log, so nothing consumes newsfragments/ here.
    - Fix the filesystem doc: a full URL in host doesn't work through adlfs,
      which ignores the account_url kwarg and builds its own from
      account_name, so point custom endpoints at the account_host field.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    
    * Convert custom-domain test to an account_host case
    
    The custom-domain case asserted account_url, which adlfs never reads
    (it has no account_url parameter, so it lands in **kwargs and is
    dropped). Reworked it to pin account_host instead - a real adlfs
    parameter carried through the extras overlay, and the path the
    filesystem docs now steer custom domains / private endpoints toward.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    
    * Test bare-host detection directly instead of asserting account_url
    
    The full DFS endpoint case in test_get_fs could only assert account_url,
    which adlfs never reads (it has no such parameter, so the value lands in
    **kwargs and is dropped). Replace it with a direct test of
    _bare_account_name_from_host, which pins what that case was guarding: a
    full endpoint (dotted host, scheme, port or path) is never treated as a
    bare account name.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * Clarify ADLS connection Host and Extra settings in docs
    
    The connection page still offered a full account URL for Host, which
    fails in both the hook and the ADLS filesystem, and the filesystem page
    listed Extra keys as connection form fields, so readers looked for them
    in the form and could not find them. The comment on the no-host case
    also described adlfs behavior it does not have, which made a setup that
    cannot connect on its own look supported.
    
    * Document account_url in the ADLS connection Extra list
    
    The Host description now points hook users at account_url in Extra for a
    private endpoint or custom domain, but the Extra list did not include
    that key, and it described account_host as a general override even
    though only the ADLS filesystem reads it. List both keys and say which
    consumer reads each, so the Host text and the Extra list agree.
    
    ---------
    
    Co-authored-by: Claude Opus 4.8 <[email protected]>
---
 .../microsoft/azure/docs/connections/adls_v2.rst   |   7 +-
 .../microsoft/azure/docs/filesystems/adls.rst      |  82 +++++++++++++
 .../airflow/providers/microsoft/azure/fs/adls.py   |  37 +++++-
 .../tests/unit/microsoft/azure/fs/test_adls.py     | 134 ++++++++++++++++++++-
 4 files changed, 250 insertions(+), 10 deletions(-)

diff --git a/providers/microsoft/azure/docs/connections/adls_v2.rst 
b/providers/microsoft/azure/docs/connections/adls_v2.rst
index 28156c74773..f6d28fdca0f 100644
--- a/providers/microsoft/azure/docs/connections/adls_v2.rst
+++ b/providers/microsoft/azure/docs/connections/adls_v2.rst
@@ -58,7 +58,9 @@ Password (optional)
     It can be left out to fall back on DefaultAzureCredential_.
 
 Host (optional)
-    Specify the account url for anonymous public read, Active Directory, 
shared access key authentication.
+    Specify the storage account name, for example ``mystorageaccount``, rather 
than a full URL.
+    For a private endpoint or custom domain, set ``account_url`` in Extra for 
the hook, or
+    ``account_host`` for the ADLS filesystem used by ``ObjectStoragePath``.
     It can be left out to fall back on DefaultAzureCredential_.
 
 Extra (optional)
@@ -67,7 +69,8 @@ Extra (optional)
 
     * ``tenant_id``: Specify the tenant to use. Needed for Active Directory 
(token) authentication. It can be left out to fall back on 
DefaultAzureCredential_.
     * ``connection_string``: Connection string for use with connection string 
authentication. It can be left out to fall back on DefaultAzureCredential_.
-    * ``account_host``: Override for the default Azure Blob endpoint domain. 
Use this to specify a custom or private domain (e.g., 
`myaccount.blob.core.customdomain.io`) instead of the default 
`core.windows.net`.
+    * ``account_url``: Full account URL for the hook to use instead of 
``https://<host>.dfs.core.windows.net``, for example for a private endpoint or 
custom domain. The ADLS filesystem used by ``ObjectStoragePath`` does not read 
it; use ``account_host`` there.
+    * ``account_host``: Override for the default Azure Blob endpoint domain. 
Use this to specify a custom or private domain (e.g., 
`myaccount.blob.core.customdomain.io`) instead of the default 
`core.windows.net`. Read by the ADLS filesystem used by ``ObjectStoragePath``; 
the hook uses ``account_url`` instead.
 
 
 When specifying the connection in environment variable you should specify
diff --git a/providers/microsoft/azure/docs/filesystems/adls.rst 
b/providers/microsoft/azure/docs/filesystems/adls.rst
new file mode 100644
index 00000000000..c12e71e1017
--- /dev/null
+++ b/providers/microsoft/azure/docs/filesystems/adls.rst
@@ -0,0 +1,82 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+Azure Data Lake Storage Gen2 Filesystem
+=======================================
+
+The Azure Data Lake Storage Gen2 filesystem provides access to ADLS Gen2
+through Airflow's ObjectStoragePath interface.
+
+Supported URL formats:
+
+* ``abfs://connection_id@container/path/to/file``
+* ``abfss://connection_id@container/path/to/file``
+* ``adl://connection_id@container/path/to/file``
+
+Connection Configuration
+------------------------
+
+Create an ADLS Gen2 connection in Airflow with the following parameters:
+
+* **Connection Type**: adls
+* **Host**: Storage account name, for example ``mystorageaccount``. For a 
private endpoint or
+  custom domain, set ``account_host`` in Extra (see below) rather than a full 
URL here.
+* **Login**: Client ID for Active Directory authentication
+* **Password**: Client secret for Active Directory authentication, or account 
key for shared key authentication
+
+The connection form provides additional configuration fields:
+
+* ``tenant_id``: Tenant ID for Active Directory authentication
+* ``connection_string``: ADLS Gen2 connection string; this takes precedence 
over other authentication fields
+* ``managed_identity_client_id``: Client ID of a user-assigned managed identity
+* ``workload_identity_tenant_id``: Tenant ID for workload identity 
authentication
+
+The following keys are also supported in the connection's Extra JSON:
+
+* ``account_name``: Optional explicit storage account name override
+* ``account_host``: Optional custom storage account host, for private 
endpoints or custom domains
+
+Examples
+--------
+
+Read from ADLS Gen2 with ObjectStoragePath:
+
+.. code-block:: python
+
+    from airflow.sdk import ObjectStoragePath
+
+    path = ObjectStoragePath("abfs://adls_default@raw/events.json")
+    content = path.read_text()
+
+Write to ADLS Gen2:
+
+.. code-block:: python
+
+    from airflow.sdk import ObjectStoragePath
+
+    output_path = 
ObjectStoragePath("abfss://adls_default@processed/events.json")
+    output_path.write_text('{"status": "ok"}')
+
+Requirements
+------------
+
+The Azure Data Lake Storage Gen2 filesystem requires the ``adlfs`` Python 
package.
+
+Cross-References
+----------------
+
+* :doc:`ADLS Gen2 connection </connections/adls_v2>`
diff --git 
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py 
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py
index 169d2cec313..9fcce00a16b 100644
--- a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py
+++ b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py
@@ -17,6 +17,7 @@
 from __future__ import annotations
 
 from typing import TYPE_CHECKING, Any
+from urllib.parse import urlparse
 
 from azure.identity import ClientSecretCredential
 
@@ -29,6 +30,26 @@ if TYPE_CHECKING:
 schemes = ["abfs", "abfss", "adl"]
 
 
+def _bare_account_name_from_host(host: str | None) -> str | None:
+    """
+    Return the storage account name when the host is a bare account name, else 
``None``.
+
+    A bare host such as ``mystorageaccount`` is the ADLS account name itself. 
A full host
+    like ``mystorageaccount.dfs.core.windows.net`` (or anything with a scheme, 
port or path)
+    is an endpoint and should keep the ``account_url`` handling instead.
+    """
+    if not host:
+        return None
+
+    # urlparse().hostname is already lowercased, so compare against a 
lowercased host to keep
+    # the check case-insensitive (Azure account names are lowercase anyway). 
The dot guard
+    # keeps full endpoints like "acct.dfs.core.windows.net" out of the 
account_name path.
+    hostname = urlparse(host if "://" in host else f"//{host}").hostname
+    if hostname and "." not in hostname and hostname == host.lower():
+        return hostname
+    return None
+
+
 def get_fs(conn_id: str | None, storage_options: dict[str, Any] | None = None) 
-> AbstractFileSystem:
     from adlfs import AzureBlobFileSystem
 
@@ -47,12 +68,20 @@ def get_fs(conn_id: str | None, storage_options: dict[str, 
Any] | None = None) -
     if connection_string:
         return AzureBlobFileSystem(connection_string=connection_string)
 
-    options: dict[str, Any] = {
-        "account_url": parse_blob_account_url(conn.host, conn.login),
-    }
-
     # mirror handling of custom field "client_secret_auth_config" from extras. 
Ignore if missing as AzureBlobFileSystem can handle.
     tenant_id = get_field(conn_id=conn_id, conn_type=conn_type, extras=extras, 
field_name="tenant_id")
+    options: dict[str, Any] = {}
+    account_name = _bare_account_name_from_host(conn.host)
+    if conn_type == "adls" and account_name:
+        # An ADLS Active Directory connection uses ``login`` as the client_id, 
so a bare host
+        # 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)
+    # Otherwise (adls + no host + a tenant_id) no account is set here: adlfs 
needs it from
+    # ``account_name`` in Extra or the AZURE_STORAGE_ACCOUNT_NAME environment 
variable.
+
     login = conn.login or ""
     password = conn.password or ""
     # assumption (from WasbHook) that if tenant_id is set, we want service 
principal connection
diff --git 
a/providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py 
b/providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py
index 14c1482dd76..8fed975750b 100644
--- a/providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py
+++ b/providers/microsoft/azure/tests/unit/microsoft/azure/fs/test_adls.py
@@ -23,7 +23,7 @@ from unittest import mock
 import pytest
 
 from airflow.models import Connection
-from airflow.providers.microsoft.azure.fs.adls import get_fs
+from airflow.providers.microsoft.azure.fs.adls import 
_bare_account_name_from_host, get_fs
 
 if os.environ.get("_AIRFLOW_SKIP_DB_TESTS") == "true":
     # Handle collection of the test by non-db case
@@ -97,10 +97,9 @@ def mocked_blob_file_system():
             ),
             {
                 "account_url": 
"https://testaccountname.blob.core.windows.net/";,
-                # "account_url": 
"https://testaccountid.blob.core.windows.net/";,
+                "account_name": "account_name",
                 "client_id": "testaccountname",
                 "client_secret": "password",
-                "account_name": "account_name",
                 "account_key": "account_key",
                 "sas_token": "sas_token",
                 "tenant_id": "tenant_id",
@@ -120,7 +119,6 @@ def mocked_blob_file_system():
             ),
             {
                 "account_url": 
"https://testaccountname.blob.core.windows.net/";,
-                # "account_url": 
"https://testaccountid.blob.core.windows.net/";,
                 "account_key": "password",
             },
         ),
@@ -141,9 +139,137 @@ def mocked_blob_file_system():
                 "account_key": "password",
             },
         ),
+        (
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                host="testaccountname",
+                login="client_id",
+                password="client_secret",
+                extra={
+                    "tenant_id": "tenant_id",
+                },
+            ),
+            {
+                "account_name": "testaccountname",
+                "client_id": "client_id",
+                "client_secret": "client_secret",
+                "tenant_id": "tenant_id",
+            },
+        ),
+        (
+            # A mixed-case bare host is still an account name; urlparse 
lowercases it.
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                host="MyAccount",
+                login="client_id",
+                password="client_secret",
+                extra={
+                    "tenant_id": "tenant_id",
+                },
+            ),
+            {
+                "account_name": "myaccount",
+                "client_id": "client_id",
+                "client_secret": "client_secret",
+                "tenant_id": "tenant_id",
+            },
+        ),
+        (
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                host="testaccountname",
+                password="account_key",
+                extra={},
+            ),
+            {
+                "account_name": "testaccountname",
+                "account_key": "account_key",
+            },
+        ),
+        (
+            # Custom domain / private endpoint: adls connections set 
account_host (a real
+            # adlfs parameter, carried through the extras overlay) rather than 
a full URL in
+            # host, which adlfs would ignore. This is the path the filesystem 
docs point at.
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                host="testaccountname",
+                login="client_id",
+                password="client_secret",
+                extra={
+                    "tenant_id": "tenant_id",
+                    "account_host": "custom.blob.core.mydomain.io",
+                },
+            ),
+            {
+                "account_name": "testaccountname",
+                "account_host": "custom.blob.core.mydomain.io",
+                "client_id": "client_id",
+                "client_secret": "client_secret",
+                "tenant_id": "tenant_id",
+            },
+        ),
+        (
+            # No host and no account_name in Extra: get_fs sets no account, so 
adlfs needs
+            # AZURE_STORAGE_ACCOUNT_NAME to connect. This pins the options 
passed, not a
+            # configuration that works on its own; the next case supplies the 
account.
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                login="client_id",
+                password="client_secret",
+                extra={
+                    "tenant_id": "tenant_id",
+                },
+            ),
+            {
+                "client_id": "client_id",
+                "client_secret": "client_secret",
+                "tenant_id": "tenant_id",
+            },
+        ),
+        (
+            Connection(
+                conn_id="testconn",
+                conn_type="adls",
+                login="client_id",
+                password="client_secret",
+                extra={
+                    "account_name": "testaccountname",
+                    "tenant_id": "tenant_id",
+                },
+            ),
+            {
+                "account_name": "testaccountname",
+                "client_id": "client_id",
+                "client_secret": "client_secret",
+                "tenant_id": "tenant_id",
+            },
+        ),
     ],
     indirect=["mocked_connection"],
 )
 def test_get_fs(mocked_connection, expected_options, mocked_blob_file_system):
     get_fs(mocked_connection.conn_id)
     mocked_blob_file_system.assert_called_once_with(**expected_options)
+
+
[email protected](
+    ("host", "expected"),
+    [
+        ("testaccountname", "testaccountname"),
+        # Full endpoints (dotted host, scheme, port or path) are not bare 
account names, so
+        # they never reach the account_name path.
+        ("testaccountname.dfs.core.windows.net", None),
+        ("https://testaccountname.blob.core.windows.net";, None),
+        ("testaccountname:443", None),
+        ("testaccountname/container", None),
+        ("", None),
+        (None, None),
+    ],
+)
+def test_bare_account_name_from_host(host, expected):
+    assert _bare_account_name_from_host(host) == expected

Reply via email to