-
Notifications
You must be signed in to change notification settings - Fork 165
refactor(BA-2966): Explicitly raise error when operation fails in auth repository #7177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Explicitly raise error when operation fails in auth repository |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,13 @@ | |
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| from typing import Optional | ||
| from typing import Any, Optional | ||
| from uuid import UUID | ||
|
|
||
| import sqlalchemy as sa | ||
| from sqlalchemy.orm import joinedload, selectinload | ||
|
|
||
| from ai.backend.common.exception import BackendAIError | ||
| from ai.backend.common.exception import BackendAIError, UserNotFound | ||
| from ai.backend.common.metrics.metric import DomainType, LayerType | ||
| from ai.backend.common.resilience.policies.metrics import MetricArgs, MetricPolicy | ||
| from ai.backend.common.resilience.policies.retry import BackoffStrategy, RetryArgs, RetryPolicy | ||
|
|
@@ -124,8 +125,8 @@ async def insert_user_with_keypair( | |
| return self._user_row_to_data(user_row) | ||
|
|
||
| @auth_db_source_resilience.apply() | ||
| async def modify_user_full_name(self, email: str, domain_name: str, full_name: str) -> bool: | ||
| """Modify user's full name in database. Returns True if updated, False if user not found.""" | ||
| async def modify_user_full_name(self, email: str, domain_name: str, full_name: str) -> None: | ||
| """Modify user's full name in database.""" | ||
| async with self._db.begin() as conn: | ||
| query = ( | ||
| sa.select(users) | ||
|
|
@@ -135,12 +136,11 @@ async def modify_user_full_name(self, email: str, domain_name: str, full_name: s | |
| result = await conn.execute(query) | ||
| user_row = result.first() | ||
| if not user_row: | ||
| return False | ||
| raise UserNotFound(extra_data={"email": email, "domain": domain_name}) | ||
|
|
||
| data = {"full_name": full_name} | ||
| update_query = users.update().values(data).where(users.c.email == email) | ||
| await conn.execute(update_query) | ||
| return True | ||
|
|
||
| @auth_db_source_resilience.apply() | ||
| async def modify_user_password(self, email: str, password_info: PasswordInfo) -> None: | ||
|
|
@@ -239,7 +239,7 @@ async def verify_credential_with_migration( | |
| domain_name: str, | ||
| email: str, | ||
| target_password_info: PasswordInfo, | ||
| ) -> Optional[dict]: | ||
| ) -> dict[str, Any]: | ||
| """Verify credentials with password migration support.""" | ||
| return await check_credential_with_migration( | ||
| db=self._db, | ||
|
|
@@ -254,7 +254,7 @@ async def verify_credential_without_migration( | |
| domain_name: str, | ||
| email: str, | ||
| password: str, | ||
| ) -> Optional[dict]: | ||
| ) -> dict[str, Any]: | ||
| """Verify credentials without password migration (for signout, etc.)""" | ||
| return await check_credential( | ||
| db=self._db, | ||
|
|
@@ -264,10 +264,21 @@ async def verify_credential_without_migration( | |
| ) | ||
|
|
||
| @auth_db_source_resilience.apply() | ||
| async def fetch_user_row_by_uuid(self, user_uuid: UUID) -> Optional[UserRow]: | ||
| async def fetch_user_row_by_uuid(self, user_uuid: UUID) -> UserRow: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserRow should not be passed outside the repository, so please fix this as well this time. |
||
| """Fetch user row by UUID from database.""" | ||
| async with self._db.begin_session() as db_session: | ||
| return await UserRow.query_user_by_uuid(user_uuid, db_session) | ||
| user_query = ( | ||
| sa.select(UserRow) | ||
| .where(UserRow.uuid == user_uuid) | ||
| .options( | ||
| joinedload(UserRow.main_keypair), | ||
| selectinload(UserRow.keypairs), | ||
| ) | ||
| ) | ||
| user_row = await db_session.scalar(user_query) | ||
| if user_row is None: | ||
| raise UserNotFound(extra_data=user_uuid) | ||
| return user_row | ||
|
|
||
| @auth_db_source_resilience.apply() | ||
| async def fetch_current_time(self) -> datetime: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the things that return dict this time to return dataclass based on the values being used? @seedspirit