Commit f74aae00 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

fix: prune stale deployment records on app deletion

parent 9ceae06b
Loading
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -89,7 +89,8 @@ def delete_app(federation_context_id, app_id, bearer_token=None, partner_api_roo

    # Check if there are application deployments dependents of the onboarding
    if check_child_onboarding(federation_context_id, app_id):
        raise APIError(409, "Unable to remove application. There are running instances. Remove them and try again ")
        # Clean up stale deployment bookkeeping records so onboarding can be removed
        _prune_orphan_deployment_records(federation_context_id, app_id)

    # Delete onboarding at edgecloud_client
    try:
@@ -468,6 +469,16 @@ def fill_update_application_onboarding_mongo_document(body, originating_ao_insta
    return onboarding_update_data


def _prune_orphan_deployment_records(federation_context_id, app_id):
    """Remove deployment bookkeeping records that have no live instances."""
    originating_ad_objects = OriginatingApplicationDeploymentManagement.objects(
        orig_ad_federation_context_id=federation_context_id,
        orig_ad_app_id=app_id
    )
    if originating_ad_objects:
        originating_ad_objects.delete()


def check_child_onboarding(federation_context_id, app_id):
    found = False