KeyError: 'sdk_moniker' while fetching parquet from ADLS Gen2 using Padas API via abfs protocol
- adlfs:
- 2023.8.0:
- Linux:
- 3.9:
Describe the bug I am reading parquet from ADLS Gen2 via Pandas API. Everything was working fine till this morning. Today, when I am running the code to fetch a parquet from ADLS, I am getting below error
2023-09-12 21:42:51 df = pd.read_parquet(f"abfs://{container_name}@{adls_account_name}.dfs.core.windows.net/{get_ds_prefix()}/{schema_name}/{table_name}",
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/pandas/io/parquet.py", line 493, in read_parquet
2023-09-12 21:42:51 return impl.read(
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/pandas/io/parquet.py", line 233, in read
2023-09-12 21:42:51 path_or_handle, handles, kwargs["filesystem"] = _get_path_or_handle(
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/pandas/io/parquet.py", line 84, in _get_path_or_handle
2023-09-12 21:42:51 fs, path_or_handle = fsspec.core.url_to_fs(
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/fsspec/core.py", line 377, in url_to_fs
2023-09-12 21:42:51 chain = _un_chain(url, kwargs)
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/fsspec/core.py", line 325, in _un_chain
2023-09-12 21:42:51 cls = get_filesystem_class(protocol)
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/fsspec/registry.py", line 234, in get_filesystem_class
2023-09-12 21:42:51 register_implementation(protocol, _import_class(bit["class"]))
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/fsspec/registry.py", line 269, in _import_class
2023-09-12 21:42:51 mod = importlib.import_module(mod)
2023-09-12 21:42:51 File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module
2023-09-12 21:42:51 return _bootstrap._gcd_import(name[level:], package, level)
2023-09-12 21:42:51 File "
I did some research on my side to see which package is causing this issue. I found adlfs package was updated on 8th August. and azure-storage-blob (this package is the prereq for adlfs) package was updated today (12th September). My guess was, that I am having updates from either of the two packages. So I explicitly specified the older version (azure-storage-file-datalake==12.12.0, adlfs==2023.4.0), but I am still having the same issue.
I looked at the PRs to get more context on the changes made to the package. and I found UserAgent was modified for the requests which are using client-side encryption.
To Reproduce Steps to reproduce the behavior:
- df = pd.read_parquet(f"abfs://{container_name}@{adls_account_name}.dfs.core.windows.net/{get_ds_prefix()}/{schema_name}/{table_name}", storage_options={'account_key': adls_account_key})
Expected behavior It should work with the old code.
Additional context The changes to the Package which is causing the issue were made at https://github.com/Azure/azure-sdk-for-python/pull/31333
I have added a temporary fix by using the old version of azure-storage-blob (azure-storage-blob==12.17.0). The current version is 12.18.0
I think I found the issue.
https://github.com/fsspec/adlfs/blob/4b704b1a5f39ec2350a8be44d9cb117aee9b1719/adlfs/spec.py#L222
In the above line, we are calling the create_configuration function, but we are not passing sdk_moniker. I checked the git blame, the line was written 3 years ago. So seems like we missed passing the sdk_moniker value here.
I also looked for other references for the create_configuration. and found one where it is called correctly. https://github.com/Azure/azure-sdk-for-python/blob/bd006c2e68d2419776fa3997848f72e4263e4009/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py#L232 .In the constructor of the class which is calling this function we have set the value sdk_moniker and also it is being passed as a named parameter.
So, if in this line https://github.com/fsspec/adlfs/blob/4b704b1a5f39ec2350a8be44d9cb117aee9b1719/adlfs/spec.py#L222, we can pass the default value, we should be good. And for the default value, since we know, the service type is a blob, we can explicitly set the default value to f"storage-blob/{VERSION}"
Looks like this is a breaking change for users since, azure-storage-blob pre 12.18.0 looks like this:
config.user_agent_policy = UserAgentPolicy(
sdk_moniker=(f"storage-{kwargs.pop('storage_skd')}/{VERSION}", **kwargs)
)
and, it now look like this:
config.user_agent_policy = UserAgentPolicy(sdk_moniker=kwargs.pop('sdk_moniker'), **kwargs)
Effectively, if you pass in sdk_moniker in a version before 12.18.0 you'll get both a dynamically generated skd_moniker, and the one you've specified, throwing an error.
If you don't pass one in for version 12.18.0, you'll get an error.
This means without doing some hula-hooping of "what version of azure-storage-blob is this?" conditionals you can't use create_configuration in a way that runs without error on version 12.18.0 and previous versions.
I don't know this project very well in terms of what the goal is for whether sdk_moniker should be a required keyword argument or not going forwards, but the fix (unless a breaking change is deliberate) seems to be to patch in "sdk_moniker" if it isn't in kwargs, and then just use "**kwargs".
Putting a PR in over the next few minutes.
I am also affected by this issue. Downgrading to 12.17.0 makes the issue disappear. I hope the patch will be released asap.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.
Hi all, thanks for the reports and the investigation. This was indeed an unintentional breaking change introduced in the latest release however, this method is intended to be private (not exported and in a package prefixed with _) and not called by users. adlfs really should not be reaching into private package imports to grab and use this:
https://github.com/fsspec/adlfs/blob/4b704b1a5f39ec2350a8be44d9cb117aee9b1719/adlfs/spec.py#L26
However, given the adlfs package is very popular and this did unintentionally break them, I will work on getting a patch release out for this today/tomorrow. After which, I will open an issue to adlfs to address this. Thanks.
Update: Just created #32071 to fix the issue on the SDK side and prepare for patch releases. The patch release should be out later today/tomorrow. Thanks.
azure-storage-blob 12.18.1 was just released which should contain the fix for this. Closing this issue. Thanks again for everyone's help.