mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix an issue where the default server-group is being deleted if the load-server json file contains no servers. #6602
This commit is contained in:
committed by
GitHub
parent
fe753bd272
commit
e587ef404c
@@ -781,14 +781,15 @@ def clear_database_servers(load_user=current_user, from_setup=False):
|
||||
for server in servers:
|
||||
db.session.delete(server)
|
||||
|
||||
# Remove all groups
|
||||
groups = ServerGroup.query.filter_by(user_id=user_id)
|
||||
# Remove all servergroups except for the first
|
||||
# This matches the UI behavior in
|
||||
# web/pgadmin/browser/server_groups/__init__.py#delete
|
||||
# TODO: Investigate if we can skip the first with an `offset(1)`
|
||||
groups = ServerGroup.query.filter_by(user_id=user_id).order_by("id")
|
||||
default_sg = groups.first()
|
||||
for group in groups:
|
||||
db.session.delete(group)
|
||||
servers = Server.query.filter_by(user_id=user_id)
|
||||
|
||||
for server in servers:
|
||||
db.session.delete(server)
|
||||
if group.id != default_sg.id:
|
||||
db.session.delete(group)
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user