Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/storage/sdkutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def get_table_data_type(cli_ctx, module_name, *type_names):

def get_blob_service_by_type(cli_ctx, blob_type):
type_to_service = {
'block': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'BlockBlobService', mod='blob'),
'page': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'PageBlobService', mod='blob'),
'append': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'AppendBlobService', mod='blob')
'block': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'BlockBlobService', mod='blob', checked=False),
'page': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'PageBlobService', mod='blob', checked=False),
'append': lambda ctx: get_sdk(ctx, ResourceType.DATA_STORAGE, 'AppendBlobService', mod='blob', checked=False)
Comment on lines +28 to +30
Copy link
Member

@jiasli jiasli Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really prefer to make checked=False the default for get_sdk, otherwise it is not universal and 'NoneType' object has no attribute '__name__' will continue to happen in other command modules. (#15776 (comment))

Copy link
Member

@jiasli jiasli Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already made checked=False the default for _get_attr in #14690

def _get_attr(sdk_path, mod_attr_path, checked=False):
"""If `checked` is True, None is returned in case of import failure."""

but it only applies to get_client_class which calls _get_attr without checked:

def get_client_class(resource_type):
return _get_attr(resource_type.import_prefix, '#' + resource_type.client_name)

get_versioned_sdk will default checked to True via

def get_versioned_sdk(api_profile, resource_type, *attr_args, **kwargs):
checked = kwargs.get('checked', True)

loaded_obj = _get_attr(sdk_path, mod_attr_path, checked)

Copy link
Member Author

@evelyn-ys evelyn-ys Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I totally agree with you. It's just I was afraid of making great changes to all modules. Should we discuss whether to change the behavior or not with all module owners?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go ahead and make the change. If CI passes, we are fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python's import statement raises ImportError in case of non-existing module.

Also, checking whether the result is None is against the look before you leap practice.

}

try:
Expand Down