Skip to content

Conversation

@jopemachine
Copy link
Member

@jopemachine jopemachine commented Dec 31, 2025

resolves #7489 (BA-3489)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

@github-actions github-actions bot added size:L 100~500 LoC comp:manager Related to Manager component labels Dec 31, 2025
@jopemachine jopemachine changed the title feat(BA-3489): Implement AssociateScalingGroupWithUserGroup Action feat(BA-3489): Implement ScalingGroup User Group Association Actions Dec 31, 2025
@jopemachine jopemachine added this to the 25.19 milestone Dec 31, 2025
@HyeockJinKim HyeockJinKim force-pushed the main branch 2 times, most recently from 9552aac to 4af738e Compare December 31, 2025 15:41
@jopemachine jopemachine modified the milestones: 25.19, 26.1 Jan 5, 2026
@jopemachine jopemachine marked this pull request as ready for review January 5, 2026 09:08
Copilot AI review requested due to automatic review settings January 5, 2026 09:08
Copy link
Contributor

Copilot AI left a 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 implements actions for associating and disassociating scaling groups with user groups (projects), enabling management of scaling group-to-project relationships through the repository and service layers.

Key Changes:

  • Added AssociateScalingGroupWithUserGroupAction and DisassociateScalingGroupWithUserGroupAction classes with corresponding action results
  • Implemented repository methods for association, disassociation, and checking association existence
  • Added comprehensive unit tests for both service and repository layers covering success and edge cases

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ai/backend/manager/services/scaling_group/actions/associate_with_user_group.py New action class for associating scaling groups with user groups
src/ai/backend/manager/services/scaling_group/actions/disassociate_with_user_group.py New action class for disassociating scaling groups from user groups
src/ai/backend/manager/services/scaling_group/service.py Added service methods to handle association/disassociation operations
src/ai/backend/manager/services/scaling_group/processors.py Registered new action processors for the association operations
src/ai/backend/manager/repositories/scaling_group/repository.py Added repository interface methods for association operations and existence checks
src/ai/backend/manager/repositories/scaling_group/db_source/db_source.py Implemented database operations for association management
src/ai/backend/manager/repositories/scaling_group/creators.py Added ScalingGroupForProjectCreatorSpec for creating associations
src/ai/backend/manager/repositories/scaling_group/purgers.py New file with batch purger implementation for removing associations
tests/unit/manager/services/scaling_group/test_scaling_group_service.py Added service layer tests for association/disassociation actions
tests/unit/manager/repositories/scaling_group/test_scaling_group_repository.py Added repository tests verifying database operations and edge cases
changes/7654.feature.md Changelog entry documenting the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +569 to +596
async def test_associate_scaling_group_with_user_group_success(
self,
scaling_group_repository: ScalingGroupRepository,
sample_scaling_group_for_purge: str,
test_user_domain_group: tuple[uuid.UUID, str, uuid.UUID],
) -> None:
"""Test associating a scaling group with a user group (project)."""
# Given: A scaling group and a project (group)
sgroup_name = sample_scaling_group_for_purge
_, _, project_id = test_user_domain_group

# When: Associate the scaling group with the project
creator = Creator(
spec=ScalingGroupForProjectCreatorSpec(
scaling_group=sgroup_name,
project=project_id,
)
)
await scaling_group_repository.associate_scaling_group_with_user_group(creator)

# Then: Association should exist
association_exists = (
await scaling_group_repository.check_scaling_group_user_group_association_exists(
scaling_group=sgroup_name,
user_group=project_id,
)
)
assert association_exists is True
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no test case to verify the behavior when attempting to associate a scaling group with a user group that is already associated. Given the unique constraint on the (scaling_group, group) columns in ScalingGroupForProjectRow, attempting to create a duplicate association should be tested to ensure proper error handling.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
Implement ScalingGroup User Group Association, Disassociation Actions
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog filename uses issue number 7654, but the PR description indicates this resolves issue #7489 (BA-3489). The filename should match the issue number referenced in the PR.

Suggested change
Implement ScalingGroup User Group Association, Disassociation Actions
#7489 (BA-3489): Implement ScalingGroup User Group Association and Disassociation actions

Copilot uses AI. Check for mistakes.
) -> None:
"""Associates a single scaling group with a user group (project)."""
async with self._db.begin_session() as session:
await execute_creator(session, creator)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The associate_scaling_group_with_user_group method doesn't handle IntegrityError exceptions that would occur when trying to create a duplicate association. The ScalingGroupForProjectRow table has a unique constraint on (scaling_group, group), so attempting to associate the same scaling group with the same project twice will raise an IntegrityError. This should be caught and converted to a more meaningful domain-specific exception, similar to how the create_scaling_group method handles duplicate scaling group names.

Suggested change
await execute_creator(session, creator)
try:
await execute_creator(session, creator)
except sa.exc.IntegrityError:
# Convert duplicate association DB error into a domain-specific conflict.
raise ScalingGroupConflict(
"Scaling group is already associated with the specified user group."
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement UserGroup Association Actions

2 participants