diff --git a/web/pgadmin/misc/workspaces/__init__.py b/web/pgadmin/misc/workspaces/__init__.py index a5ae5c662..b3193a2bc 100644 --- a/web/pgadmin/misc/workspaces/__init__.py +++ b/web/pgadmin/misc/workspaces/__init__.py @@ -176,6 +176,17 @@ def adhoc_connect_server(): # Clone the server object server = server.clone() + # Server.clone() copies every column from the source row, + # including user_id/shared/shared_username. When the source + # is another user's shared server, the clone must not inherit + # that ownership: force the new adhoc record to belong to the + # current user and to be private, otherwise a non-owner ends + # up persisting a cross-tenant, administrator-owned server + # row. + server.user_id = current_user.id + server.shared = False + server.shared_username = None + # Replace the following with the new/changed value. server.maintenance_db = new_db server.username = new_username