dabla commented on code in PR #77376:
URL: https://github.com/apache/airflow/pull/77376#discussion_r4697095324
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py:
##########
@@ -30,22 +30,41 @@
schemes = ["abfs", "abfss", "adl"]
+def _hostname_from_host(host: str | None) -> str | None:
+ if not host:
+ return None
+ return urlparse(host if "://" in host else f"//{host}").hostname
+
+
+def _account_host_from_host(host: str | None) -> str | None:
+ if not host:
+ return None
+ parsed = urlparse(host if "://" in host else f"//{host}")
Review Comment:
**[warning]** `_account_host_from_host` repeats the parse of
`_hostname_from_host`, six lines above it.
Both helpers start with the same `if not host: return None` and the same
`urlparse(host if "://" in host else f"//{host}")`, and `get_fs` calls them one
after the other on `conn.host` (lines 113 and 118), so the host is parsed twice
by two copies of one rule. One helper that returns the parsed result, with the
hostname and the account host both read from it, keeps the scheme-less handling
in a single place. While there: the `except ValueError` around `parsed.port`
drops an invalid port silently and no test reaches it; either let it raise, as
a malformed host is a configuration error, or cover it with a case.
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py:
##########
@@ -77,8 +96,32 @@ 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)
+ # adlfs has no account_url parameter and would silently drop it; it
reads
+ # account_name and builds the URL from account_host, so derive both
from
+ # the host. Only an endpoint host (a hostname with a dot, the same
+ # parsing _bare_account_name_from_host uses) supplies an account_host,
+ # and only when it is not the default blob host, which adlfs already
+ # defaults to. The name and host come from the parsed hostname, not the
+ # rebuilt account URL: parse_blob_account_url misreads a host with a
+ # port and no scheme as a scheme, and would build the URL from the
+ # login instead. A bare identifier is not an endpoint, and for those
+ # parse_blob_account_url builds the URL from the login. A bare login is
+ # the account name (wasb shared key), but with a tenant id the login
is a
+ # service principal client id, so without an endpoint host nothing is
+ # derived and adlfs falls back to account_name from extras or the
+ # AZURE_STORAGE_ACCOUNT_NAME env var.
+ conn_hostname = _hostname_from_host(conn.host)
+ host_is_endpoint = conn_hostname is not None and "." in conn_hostname
+ if host_is_endpoint:
+ derived_account_name = conn_hostname.split(".")[0]
Review Comment:
**[blocker]** This line fails mypy, so the static checks will go red once CI
runs on this commit.
mypy does not narrow `conn_hostname` through the `host_is_endpoint` boolean,
so inside `if host_is_endpoint:` it is still `str | None`. Running mypy 2.4.1
with the repository's configuration on this head:
```
providers/microsoft/azure/src/airflow/providers/microsoft/azure/fs/adls.py:116:
error:
Item "None" of "str | None" has no attribute "split" [union-attr]
derived_account_name = conn_hostname.split(".")[0]
```
Before this commit the branch read `account_url.hostname` behind its own
`if`, which is why the previous head passed. Testing the value directly narrows
it: `if conn_hostname and "." in conn_hostname:`, with the `elif` unchanged.
The project CI has not run on `d09a354d37` (see the summary), so this does not
show on the PR yet.
--
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]