azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

KeyError: 'sdk_moniker' while fetching parquet from ADLS Gen2 using Padas API via abfs protocol

Open nadeem4 opened this issue 3 years ago • 8 comments

  • 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 "", line 1030, in _gcd_import 2023-09-12 21:42:51 File "", line 1007, in _find_and_load 2023-09-12 21:42:51 File "", line 986, in _find_and_load_unlocked 2023-09-12 21:42:51 File "", line 680, in _load_unlocked 2023-09-12 21:42:51 File "", line 850, in exec_module 2023-09-12 21:42:51 File "", line 228, in _call_with_frames_removed 2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/adlfs/init.py", line 3, in 2023-09-12 21:42:51 from .spec import AzureBlobFile, AzureBlobFileSystem 2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/adlfs/spec.py", line 115, in 2023-09-12 21:42:51 class AzureBlobFileSystem(AsyncFileSystem): 2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/adlfs/spec.py", line 213, in AzureBlobFileSystem 2023-09-12 21:42:51 blocksize: int = create_configuration(storage_sdk="blob").max_block_size, 2023-09-12 21:42:51 File "/usr/local/lib/python3.9/site-packages/azure/storage/blob/_shared/base_client.py", line 415, in create_configuration 2023-09-12 21:42:51 config.user_agent_policy = UserAgentPolicy(sdk_moniker=kwargs.pop('sdk_moniker'), **kwargs) 2023-09-12 21:42:51 KeyError: 'sdk_moniker'

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:

  1. 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

nadeem4 avatar Sep 13 '23 03:09 nadeem4

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

nadeem4 avatar Sep 13 '23 04:09 nadeem4

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}"

nadeem4 avatar Sep 13 '23 04:09 nadeem4

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.

benrutter avatar Sep 13 '23 10:09 benrutter

I am also affected by this issue. Downgrading to 12.17.0 makes the issue disappear. I hope the patch will be released asap.

francesco086 avatar Sep 13 '23 13:09 francesco086

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

github-actions[bot] avatar Sep 13 '23 17:09 github-actions[bot]

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.

jalauzon-msft avatar Sep 13 '23 17:09 jalauzon-msft

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.

jalauzon-msft avatar Sep 13 '23 19:09 jalauzon-msft

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.

jalauzon-msft avatar Sep 13 '23 23:09 jalauzon-msft