Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(apps): name-clash errors point at the Recycle Bin for tombstones

Juan Denis1b9f0061c74a
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index 6c2b8108..a97b54d7 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -12,7 +12,7 @@ from sqlalchemy.orm import joinedload
from app import db
from app.api._query import apply_query, QueryParseError
from app.models import Application, User
-from app.utils.slug import slugify
+from app.utils.slug import app_name_clash_error, slugify
from app.services.build_service import BuildService
from app.services.docker_service import DockerService
from app.services.git_service import GitService
@@ -840,8 +840,10 @@ def create_app_from_repository():
# NOT query_active: a tombstone keeps reserving its name (and, below, its
# directory under APPS_DIR). Letting a new app take the name of one sitting
# in the recycle bin would make the restore collide.
- if Application.query.filter_by(name=name, server_id=None).first():
- return jsonify({'error': f'An application named "{name}" already exists'}), 400
+ clash = app_name_clash_error(
+ Application.query.filter_by(name=name, server_id=None).first(), name)
+ if clash:
+ return jsonify({'error': clash}), 400
try:
app_path = _assert_managed_app_path(name)
@@ -1123,8 +1125,10 @@ def create_manual_app():
# NOT query_active: a tombstone keeps reserving its name so a restore can't
# collide with an app created in the meantime.
- if Application.query.filter_by(name=name).first():
- return jsonify({'error': f'An application named "{name}" already exists'}), 400
+ clash = app_name_clash_error(
+ Application.query.filter_by(name=name).first(), name)
+ if clash:
+ return jsonify({'error': clash}), 400
from app.services.workspace_service import WorkspaceService
ws_id = WorkspaceService.resolve_workspace_id(
@@ -1223,7 +1227,7 @@ def upload_app_archive():
else:
if existing:
os.remove(zippath)
- return jsonify({'error': f'An application named "{name}" already exists'}), 400
+ return jsonify({'error': app_name_clash_error(existing, name)}), 400
new_version = 1
version_dir = extract_version(app_dir, zippath, new_version)
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.py
index 5ade2059..fa4bf93b 100644
--- a/backend/app/api/templates.py
+++ b/backend/app/api/templates.py
@@ -18,7 +18,7 @@ from app.services.deployment_job_service import DeploymentJobService
from app.services.template_service import TemplateService
from app.services.repository_manifest_service import RepositoryManifestService
from app.services.resource_grant_service import ResourceGrantService
-from app.utils.slug import validate_app_name
+from app.utils.slug import app_name_clash_error, validate_app_name
from app.error_reporting import unexpected_response
templates_bp = Blueprint('templates', __name__)
@@ -410,7 +410,7 @@ def validate_installation():
if app_name:
existing = Application.query.filter_by(name=app_name).first()
if existing:
- errors.append(f'An application named "{app_name}" already exists')
+ errors.append(app_name_clash_error(existing, app_name))
# Validate template exists and check required variables
if template_id:
diff --git a/backend/app/services/deployment_job_service.py b/backend/app/services/deployment_job_service.py
index a4cc6d0f..7ab6cca8 100644
--- a/backend/app/services/deployment_job_service.py
+++ b/backend/app/services/deployment_job_service.py
@@ -14,6 +14,7 @@ from app.services.run_log_service import append_log, stream_for
from app.services.docker_service import DockerService
from app.services.template_service import TemplateService
from app.services.telemetry_service import generate_correlation_id
+from app.utils.slug import app_name_clash_error
# Unified job kinds (see register_jobs()): asynchronous template installs,
# builds/deploys of existing apps (e.g. repo-based services from Flow A), and
@@ -49,7 +50,8 @@ class DeploymentJobService:
if existing:
return {
'success': False,
- 'error': f'An application named "{app_name}" already exists on this target server'
+ 'error': app_name_clash_error(existing, app_name,
+ suffix=' on this target server')
}
if normalized_server_id:
diff --git a/backend/app/utils/slug.py b/backend/app/utils/slug.py
index 68c28c92..1a7db5b5 100644
--- a/backend/app/utils/slug.py
+++ b/backend/app/utils/slug.py
@@ -119,3 +119,26 @@ def validate_app_name(name, min_length=3, max_length=63,
if reserved and name.lower() in {r.lower() for r in reserved}:
return False, f'Name "{name}" is reserved'
return True, None
+
+
+def app_name_clash_error(existing, name, suffix=''):
+ """Message for a taken application name, or ``None`` when it is free.
+
+ A soft-deleted app deliberately keeps reserving its name (a restore must
+ never collide), but "already exists" sends the operator hunting for an app
+ that is not in any list — so a tombstone names the Recycle Bin instead.
+
+ Args:
+ existing: The Application row holding the name (may be a tombstone),
+ or ``None``.
+ name: The requested name, echoed into the message.
+ suffix: Optional clause appended to the live-app message, e.g.
+ ``' on this target server'``.
+ """
+ if existing is None:
+ return None
+ if getattr(existing, 'deleted_at', None):
+ return (f'An application named "{name}" is in the Recycle Bin — '
+ 'restore it, or purge it from Settings → Recycle Bin to '
+ 'reuse the name')
+ return f'An application named "{name}" already exists{suffix}'
diff --git a/backend/tests/test_application_soft_delete.py b/backend/tests/test_application_soft_delete.py
index da735e24..307d44a5 100644
--- a/backend/tests/test_application_soft_delete.py
+++ b/backend/tests/test_application_soft_delete.py
@@ -263,3 +263,28 @@ def test_a_tombstoned_app_keeps_its_domains(app, live_app):
db.session.commit()
assert Domain.query.filter_by(application_id=live_app.id).count() == 1
+
+
+# ------------------------------------------------ naming the name reservation
+
+def test_a_tombstone_clash_names_the_recycle_bin(app, client, auth_headers, dead_app):
+ """The reservation is deliberate, but "already exists" points at an app
+ that is in no list — the message must say where the name is being held
+ and how to release it (GH report: delete an app, can't reuse the name)."""
+ res = client.post('/api/v1/templates/validate-install', headers=auth_headers,
+ json={'template_id': 'actualbudget', 'app_name': 'shop'})
+
+ assert res.status_code == 400
+ errors = ' '.join(res.get_json()['errors'])
+ assert 'Recycle Bin' in errors
+ assert 'purge' in errors
+
+
+def test_a_live_clash_keeps_the_plain_already_exists(app, client, auth_headers, live_app):
+ res = client.post('/api/v1/templates/validate-install', headers=auth_headers,
+ json={'template_id': 'actualbudget', 'app_name': 'shop'})
+
+ assert res.status_code == 400
+ errors = ' '.join(res.get_json()['errors'])
+ assert 'already exists' in errors
+ assert 'Recycle Bin' not in errors