Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default ServerGroup to user loading 0 Servers #6855

Merged
15 changes: 8 additions & 7 deletions web/pgadmin/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
benjaminjb marked this conversation as resolved.
Show resolved Hide resolved
# 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()
Expand Down