Skip to content

Commit accd498

Browse files
authored
Document and handle None input to _from_workspace_connection_rest_object (Azure#28174)
1 parent 1674be1 commit accd498

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_credentials.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ def _to_workspace_connection_rest_object(self) -> RestWorkspaceConnectionSharedA
109109

110110
@classmethod
111111
def _from_workspace_connection_rest_object(
112-
cls, obj: RestWorkspaceConnectionSharedAccessSignature
112+
cls, obj: Optional[RestWorkspaceConnectionSharedAccessSignature]
113113
) -> "SasTokenConfiguration":
114-
return cls(sas_token=obj.sas if obj.sas else None)
114+
return cls(sas_token=obj.sas if obj is not None and obj.sas else None)
115115

116116
def __eq__(self, other: object) -> bool:
117117
if not isinstance(other, SasTokenConfiguration):
@@ -139,9 +139,9 @@ def _to_workspace_connection_rest_object(self) -> RestWorkspaceConnectionPersona
139139

140140
@classmethod
141141
def _from_workspace_connection_rest_object(
142-
cls, obj: RestWorkspaceConnectionPersonalAccessToken
142+
cls, obj: Optional[RestWorkspaceConnectionPersonalAccessToken]
143143
) -> "PatTokenConfiguration":
144-
return cls(pat=obj.pat if obj and obj.pat else None)
144+
return cls(pat=obj.pat if obj is not None and obj.pat else None)
145145

146146
def __eq__(self, other: object) -> bool:
147147
if not isinstance(other, PatTokenConfiguration):
@@ -174,11 +174,11 @@ def _to_workspace_connection_rest_object(self) -> RestWorkspaceConnectionUsernam
174174

175175
@classmethod
176176
def _from_workspace_connection_rest_object(
177-
cls, obj: RestWorkspaceConnectionUsernamePassword
177+
cls, obj: Optional[RestWorkspaceConnectionUsernamePassword]
178178
) -> "UsernamePasswordConfiguration":
179179
return cls(
180-
username=obj.username if obj and obj.username else None,
181-
password=obj.password if obj and obj.password else None,
180+
username=obj.username if obj is not None and obj.username else None,
181+
password=obj.password if obj is not None and obj.password else None,
182182
)
183183

184184
def __eq__(self, other: object) -> bool:
@@ -244,12 +244,12 @@ def _to_workspace_connection_rest_object(self) -> RestWorkspaceConnectionService
244244

245245
@classmethod
246246
def _from_workspace_connection_rest_object(
247-
cls, obj: RestWorkspaceConnectionServicePrincipal
247+
cls, obj: Optional[RestWorkspaceConnectionServicePrincipal]
248248
) -> "ServicePrincipalConfiguration":
249249
return cls(
250-
client_id=obj.client_id if obj.client_id else None,
251-
client_secret=obj.client_secret if obj.client_secret else None,
252-
tenant_id=obj.tenant_id if obj.tenant_id else None,
250+
client_id=obj.client_id if obj is not None and obj.client_id else None,
251+
client_secret=obj.client_secret if obj is not None and obj.client_secret else None,
252+
tenant_id=obj.tenant_id if obj is not None and obj.tenant_id else None,
253253
authority_url=None,
254254
)
255255

@@ -396,11 +396,11 @@ def _to_workspace_connection_rest_object(self) -> RestWorkspaceConnectionManaged
396396

397397
@classmethod
398398
def _from_workspace_connection_rest_object(
399-
cls, obj: RestWorkspaceConnectionManagedIdentity
399+
cls, obj: Optional[RestWorkspaceConnectionManagedIdentity]
400400
) -> "ManagedIdentityConfiguration":
401401
return cls(
402-
client_id=obj.client_id if obj else None,
403-
resource_id=obj.resource_id if obj else None,
402+
client_id=obj.client_id if obj is not None and obj.client_id else None,
403+
resource_id=obj.resource_id if obj is not None and obj.client_id else None,
404404
)
405405

406406
def _to_job_rest_object(self) -> RestJobManagedIdentity:

0 commit comments

Comments
 (0)