-
Notifications
You must be signed in to change notification settings - Fork 163
refactor(BA-2969, BA-2970): Introduce DB Source in container registry repository #6671
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR refactors the container registry repository layer to use a source-based architecture, extracting database operations into a separate ContainerRegistryDBSource class and converting tests from mocked unit tests to integration tests using a real database.
Key Changes:
- Extracted database access logic into a new
ContainerRegistryDBSourceclass for better separation of concerns - Converted all tests from mocked unit tests to integration tests that use real database operations
- Consolidated admin repository tests into the main test file (though test coverage was lost in the process)
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/ai/backend/manager/repositories/container_registry/repository.py |
Refactored to delegate all database operations to ContainerRegistryDBSource instead of containing DB logic directly |
src/ai/backend/manager/repositories/container_registry/admin_repository.py |
Updated to use ContainerRegistryDBSource directly instead of wrapping ContainerRegistryRepository |
src/ai/backend/manager/repositories/container_registry/db_source/db_source.py |
New file containing all database access logic extracted from the repository classes |
src/ai/backend/manager/repositories/container_registry/db_source/__init__.py |
New empty __init__.py file for the db_source package |
tests/manager/repositories/container_registry/test_container_registry_repository.py |
Converted from mocked unit tests to integration tests with real database operations and helper fixtures |
tests/manager/repositories/container_registry/test_admin_container_registry_repository.py |
Deleted - admin repository tests were intended to be consolidated but coverage was lost |
tests/manager/repositories/container_registry/BUILD |
Added explicit dependency on the manager source code |
changes/6671.enhance.md |
Added changelog entry describing the refactoring |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/manager/repositories/container_registry/test_container_registry_repository.py
Show resolved
Hide resolved
tests/manager/repositories/container_registry/test_container_registry_repository.py
Show resolved
Hide resolved
src/ai/backend/manager/repositories/container_registry/db_source/db_source.py
Show resolved
Hide resolved
src/ai/backend/manager/repositories/container_registry/db_source/db_source.py
Show resolved
Hide resolved
| async def fetch_registry_row( | ||
| self, | ||
| registry_name: str, | ||
| project: Optional[str] = None, | ||
| ) -> ContainerRegistryRow: |
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.
Depending on how the unique condition of the registry name is applied in this method, it seems like multiple values could be queried, so I need to check the behavior.
| async def fetch_known_registries(self) -> dict[str, str]: | ||
| """Fetch all known container registries from the database.""" | ||
| async with self._db.begin_readonly_session() as session: | ||
| known_registries_map = await ContainerRegistryRow.get_known_container_registries( | ||
| session | ||
| ) |
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.
Please avoid returning a dict. You should properly define and pass the data class from where you first read the value, so that subsequent logic becomes easier to read.
| .where(ImageRow.registry == registry_name) | ||
| .where(ImageRow.status != ImageStatus.DELETED) | ||
| .values(status=ImageStatus.DELETED) | ||
| ) | ||
| if project: | ||
| update_stmt = update_stmt.where(ImageRow.project == project) |
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.
We also need to check the project and registry parts once.
resolves #6643, #6644 (BA-2969, BA-2970)
Checklist: (if applicable)
ai.backend.testdocsdirectory