-
Notifications
You must be signed in to change notification settings - Fork 164
refactor(BA-3764): add Purger pattern to Domain repository #8525
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
refactor(BA-3764): add Purger pattern to Domain repository #8525
Conversation
| async def soft_delete_domain(self, domain_name: str) -> None: | ||
| """ | ||
| Soft deletes a domain by setting is_active to False. | ||
| Validates domain deletion permissions. | ||
| """ | ||
| async with self._db.begin() as conn: |
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.
soft_delete_domain() still uses SAConnection. Only purge_domain() and its helper methods were migrated to SASession in this PR.
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 domain deletion to use the BatchPurger pattern, migrating from Core SQLAlchemy operations (AsyncConnection) to ORM operations (AsyncSession). This brings consistency with other repositories in the codebase that have already adopted this pattern (e.g., GroupRepository, UserRepository).
Changes:
- Introduced
DomainKernelBatchPurgerSpecandDomainBatchPurgerSpecfor structured batch deletion operations - Migrated
purge_domain()and helper methods fromAsyncConnectiontoAsyncSession - Added integration tests for the new purger specifications
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/ai/backend/manager/repositories/domain/purgers.py | New file defining batch purger specs for domain and kernel deletions, following the established pattern in the codebase |
| src/ai/backend/manager/repositories/domain/repository.py | Updated purge_domain() to use BatchPurger pattern; migrated helper methods from Core (AsyncConnection) to ORM (AsyncSession); updated imports to use Row classes instead of table objects |
| tests/unit/manager/repositories/domain/test_domain_purgers.py | New integration tests for domain purger specs with comprehensive fixture setup and assertions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from ai.backend.manager.models.utils import ExtendedAsyncSAEngine | ||
|
|
||
|
|
||
| class TestDomainPurgersIntegration: |
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.
The initial plan included keypair_resource_policy, sample_keypair, and sample_scaling_group fixtures, but they turned out to be unnecessary for these purger spec tests. So I excluded them.
Replace raw SQL deletion with BatchPurger pattern in DomainRepository.purge_domain() for consistent and maintainable domain data deletion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Align with the group test convention where sample_domain returns a plain string instead of DomainRow object. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
asyncio_mode = "auto" is configured in pyproject.toml, making explicit @pytest.mark.asyncio decorators redundant. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…sionMap
Fix test fixtures to use ResourceSlot({}) and VFolderHostPermissionMap({})
instead of plain dict, as the model columns now require these types.
Also remove @pytest.mark.asyncio decorators (asyncio_mode=auto).
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
046eb72 to
85fb1cc
Compare
Summary
BatchPurgerpattern inDomainRepository.purge_domain()for domain-related deletionsDomainKernelBatchPurgerSpecandDomainBatchPurgerSpecfor batch deletion of kernels and domainspurge_domain()and related helper methods fromSAConnection(Core) toSASession(ORM)Related Issue
Test plan
pants lint src/ai/backend/manager/repositories/domain::pants check src/ai/backend/manager/repositories/domain::pants test tests/unit/manager/repositories/domain::🤖 Generated with Claude Code