Skip to content

Commit

Permalink
Refactor credential deletion logic to use lists instead of sets and a…
Browse files Browse the repository at this point in the history
…dd sorting for better consistency
  • Loading branch information
arash77 committed Jan 3, 2025
1 parent be6eb75 commit d6b92ae
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/galaxy/webapps/galaxy/services/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def delete_service_credentials(
):
"""Deletes all credentials for a specific service."""
user_credentials = self._user_credentials(trans, user_id=user_id, user_credentials_id=user_credentials_id)
rows_to_be_deleted = {item for uc in user_credentials for item in uc}
rows_to_be_deleted = [item for uc in user_credentials for item in uc]
rows_to_be_deleted.sort(
key=lambda item: (isinstance(item, UserCredentials), isinstance(item, CredentialsGroup))
)
self._delete_credentials(trans.sa_session, rows_to_be_deleted)

def delete_credentials(
Expand All @@ -80,7 +83,8 @@ def delete_credentials(
):
"""Deletes a specific credential group."""
user_credentials = self._user_credentials(trans, user_id=user_id, group_id=group_id)
rows_to_be_deleted = {item for uc in user_credentials for item in uc if not isinstance(item, UserCredentials)}
rows_to_be_deleted = [item for uc in user_credentials for item in uc if not isinstance(item, UserCredentials)]
rows_to_be_deleted.sort(key=lambda item: isinstance(item, CredentialsGroup))
self._delete_credentials(trans.sa_session, rows_to_be_deleted)

def _user_credentials(
Expand Down Expand Up @@ -291,7 +295,7 @@ def _create_user_credential(
credentials_dict = self._user_credentials_to_dict(new_user_credentials).values()
return UserCredentialsListResponse(root=[UserCredentialsResponse(**cred) for cred in credentials_dict])

def _delete_credentials(self, sa_session: galaxy_scoped_session, rows_to_be_deleted: set):
def _delete_credentials(self, sa_session: galaxy_scoped_session, rows_to_be_deleted: List):
for row in rows_to_be_deleted:
sa_session.delete(row)
with transaction(sa_session):
Expand Down

0 comments on commit d6b92ae

Please sign in to comment.