Roll back service creation on error

ref #202
This commit is contained in:
Tobias Kunze 2025-10-14 11:16:03 +02:00
parent 27b9133ad4
commit 72fedefb7f

View file

@ -663,6 +663,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
return mark_safe(f"<ul>{error_items}</ul>") return mark_safe(f"<ul>{error_items}</ul>")
@classmethod @classmethod
@transaction.atomic
def create_instance(cls, name, organization, context, created_by, spec_data): def create_instance(cls, name, organization, context, created_by, spec_data):
# Ensure the namespace exists # Ensure the namespace exists
context.control_plane.get_or_create_namespace(organization) context.control_plane.get_or_create_namespace(organization)
@ -710,7 +711,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
body=create_data, body=create_data,
) )
except Exception as e: except Exception as e:
instance.delete() # Transaction will automatically roll back the instance creation
if isinstance(e, ApiException): if isinstance(e, ApiException):
try: try:
error_body = json.loads(e.body) error_body = json.loads(e.body)