@@ -494,9 +494,6 @@ def get_versioned_sdk_path(api_profile, resource_type, operation_group=None):
494494 e.g. Converts azure.mgmt.storage.operations.storage_accounts_operations to
495495 azure.mgmt.storage.v2016_12_01.operations.storage_accounts_operations
496496 azure.keyvault.v7_0.models.KeyVault
497-
498- For SDKs that only support the latest API version (e.g., azure-mgmt-compute >= 36.0.0),
499- returns the unversioned path.
500497 """
501498 api_version = get_api_version (api_profile , resource_type )
502499 if api_version is None :
@@ -507,30 +504,34 @@ def get_versioned_sdk_path(api_profile, resource_type, operation_group=None):
507504 api_version = api_version ._sdk_profile .default_api_version
508505 else :
509506 api_version = getattr (api_version , operation_group )
510-
511- # Try versioned path first for backward compatibility
512- versioned_path = '{}.v{}' .format (resource_type .import_prefix , api_version .replace ('-' , '_' ).replace ('.' , '_' ))
513-
514- # Check if the versioned module exists by attempting to import it
515- try :
516- import_module (versioned_path )
517- return versioned_path
518- except ImportError :
519- # SDK doesn't support versioned paths (e.g., azure-mgmt-compute >= 36.0.0)
520- # Fall back to unversioned path
521- logger .debug ("Versioned path '%s' not found, falling back to unversioned path '%s'" ,
522- versioned_path , resource_type .import_prefix )
523- return resource_type .import_prefix
507+ return '{}.v{}' .format (resource_type .import_prefix , api_version .replace ('-' , '_' ).replace ('.' , '_' ))
524508
525509
526510def get_versioned_sdk (api_profile , resource_type , * attr_args , ** kwargs ):
527511 checked = kwargs .get ('checked' , True )
528512 sub_mod_prefix = kwargs .get ('mod' , None )
529513 operation_group = kwargs .get ('operation_group' , None )
530514 sdk_path = get_versioned_sdk_path (api_profile , resource_type , operation_group )
515+
516+ # Check if we should try unversioned path
517+ # This handles SDKs that only support the latest API version (e.g., azure-mgmt-compute >= 36.0.0)
518+ unversioned_path = resource_type .import_prefix
519+ should_try_unversioned = False
520+
521+ # Try to import the base versioned module to check if it exists
522+ if 'v' in sdk_path .split (unversioned_path , 1 )[- 1 ]:
523+ try :
524+ import_module (sdk_path .rsplit ('.' , 1 )[0 ] if '.' in sdk_path .split ('.v' , 1 )[1 ] else sdk_path )
525+ except (ImportError , IndexError ):
526+ # Versioned module doesn't exist, use unversioned path
527+ logger .debug ("Versioned SDK path '%s' not found, using unversioned path '%s'" , sdk_path , unversioned_path )
528+ sdk_path = unversioned_path
529+ should_try_unversioned = True
530+
531531 if not attr_args :
532- # No attributes to load. Return the versioned sdk
532+ # No attributes to load. Return the sdk module
533533 return import_module (sdk_path )
534+
534535 results = []
535536 for mod_attr_path in attr_args :
536537 if sub_mod_prefix and '#' not in mod_attr_path :
0 commit comments