Skip to content
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

fix queries #1638

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,15 @@ async def check_is_last_variant_for_image(db_app_variant: AppVariantDB) -> bool:
true if it's the last variant, false otherwise
"""

query_expression = {"base.id": db_app_variant.base.id}
query = AppVariantDB.find(AppVariantDB.base.id == ObjectId(db_app_variant.base.id))

if isCloudEE():
query_expression.update(
{
"organization.id": db_app_variant.organization.id,
"workspace.id": db_app_variant.workspace.id,
}
query = query.find(
AppVariantDB.organization.id == db_app_variant.organization.id,
AppVariantDB.workspace.id == db_app_variant.workspace.id,
)

count_variants = await AppVariantDB.find(query_expression).count()
count_variants = await query.count()
return count_variants == 1


Expand All @@ -1017,7 +1015,10 @@ async def remove_deployment(deployment_db: DeploymentDB):
logger.debug("Removing deployment")
assert deployment_db is not None, "deployment_db is missing"

await deployment_db.delete()
deployment = await DeploymentDB.find_one(
DeploymentDB.id == ObjectId(deployment_db.id)
)
await deployment.delete()


async def remove_app_variant_from_db(app_variant_db: AppVariantDB):
Expand All @@ -1041,7 +1042,10 @@ async def remove_app_variant_from_db(app_variant_db: AppVariantDB):
for app_variant_revision in app_variant_revisions:
await app_variant_revision.delete()

await app_variant_db.delete()
app_variant = await AppVariantDB.find_one(
AppVariantDB.id == ObjectId(app_variant_db.id)
)
await app_variant.delete()


async def deploy_to_environment(
Expand Down Expand Up @@ -1376,6 +1380,8 @@ async def remove_image(image: ImageDB):
"""
if image is None:
raise ValueError("Image is None")

image = await ImageDB.find_one(ImageDB.id == ObjectId(image.id))
await image.delete()


Expand Down
Loading