Complete fix: delete resource records when deleting resource pool

This completes the fix from PR #2315 by ensuring that when a resource
pool is deleted, all associated resource records are also deleted from
the resources table, preventing orphaned resource records.

Changes:
- Modified delete_resource_pool() to first delete all resource records
  in the pool before deleting the pool itself
- This complements the existing fix in remove_resource_from_pool() which
  handles single resource removal
This commit is contained in:
YueGuobin 2026-06-01 12:43:56 +08:00
parent fcb76a4b01
commit d2848a600e
No known key found for this signature in database

View File

@ -156,6 +156,14 @@ class ResourcePoolsRepository(BaseRepository):
Delete a resource pool.
"""
# Get all resources in the pool first
resources = await self.get_pool_resources(resource_pool_id)
# Delete all resource records
for resource in resources:
await self.delete_resource(resource.resource_id)
# Now delete the resource pool
query = delete(models.ResourcePool).where(models.ResourcePool.resource_pool_id == resource_pool_id)
result = await self._db_session.execute(query)
await self._db_session.commit()