mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Drop all connections from the connection manager when a server is dropped to avoid issues if sqlite reuses an ID. Fixes #1720
This commit is contained in:
parent
0ba414f0ab
commit
f117685d77
@ -24,6 +24,7 @@ from pgadmin.utils.menu import MenuItem
|
|||||||
import config
|
import config
|
||||||
from config import PG_DEFAULT_DRIVER
|
from config import PG_DEFAULT_DRIVER
|
||||||
from pgadmin.model import db, Server, ServerGroup, User
|
from pgadmin.model import db, Server, ServerGroup, User
|
||||||
|
from pgadmin.utils.driver import get_driver
|
||||||
|
|
||||||
|
|
||||||
def has_any(data, keys):
|
def has_any(data, keys):
|
||||||
@ -64,7 +65,6 @@ class ServerModule(sg.ServerGroupPluginModule):
|
|||||||
servers = Server.query.filter_by(user_id=current_user.id,
|
servers = Server.query.filter_by(user_id=current_user.id,
|
||||||
servergroup_id=gid)
|
servergroup_id=gid)
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||||
|
|
||||||
for server in servers:
|
for server in servers:
|
||||||
@ -156,7 +156,6 @@ class ServerModule(sg.ServerGroupPluginModule):
|
|||||||
sub-modules at once.
|
sub-modules at once.
|
||||||
"""
|
"""
|
||||||
if first_registration:
|
if first_registration:
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
driver = get_driver(PG_DEFAULT_DRIVER, app)
|
driver = get_driver(PG_DEFAULT_DRIVER, app)
|
||||||
app.jinja_env.filters['qtLiteral'] = driver.qtLiteral
|
app.jinja_env.filters['qtLiteral'] = driver.qtLiteral
|
||||||
app.jinja_env.filters['qtIdent'] = driver.qtIdent
|
app.jinja_env.filters['qtIdent'] = driver.qtIdent
|
||||||
@ -224,7 +223,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
servers = Server.query.filter_by(user_id=current_user.id,
|
servers = Server.query.filter_by(user_id=current_user.id,
|
||||||
servergroup_id=gid)
|
servergroup_id=gid)
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||||
|
|
||||||
for server in servers:
|
for server in servers:
|
||||||
@ -293,7 +291,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
connected = conn.connected()
|
connected = conn.connected()
|
||||||
@ -353,6 +350,7 @@ class ServerNode(PGChildNodeView):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
for s in servers:
|
for s in servers:
|
||||||
|
get_driver(PG_DEFAULT_DRIVER).delete_manager(s.id)
|
||||||
db.session.delete(s)
|
db.session.delete(s)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -405,7 +403,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
request.data, encoding='utf-8'
|
request.data, encoding='utf-8'
|
||||||
)
|
)
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
connected = conn.connected()
|
connected = conn.connected()
|
||||||
@ -473,7 +470,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
).first()
|
).first()
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||||
|
|
||||||
for server in servers:
|
for server in servers:
|
||||||
@ -519,7 +515,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
id=server.servergroup_id
|
id=server.servergroup_id
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||||
|
|
||||||
manager = driver.connection_manager(sid)
|
manager = driver.connection_manager(sid)
|
||||||
@ -594,7 +589,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
user = None
|
user = None
|
||||||
|
|
||||||
if 'connect_now' in data and data['connect_now']:
|
if 'connect_now' in data and data['connect_now']:
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
||||||
manager.update(server)
|
manager.update(server)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
@ -663,7 +657,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
return make_json_response(data='')
|
return make_json_response(data='')
|
||||||
|
|
||||||
def statistics(self, gid, sid):
|
def statistics(self, gid, sid):
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
@ -717,7 +710,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
|
|
||||||
def connect_status(self, gid, sid):
|
def connect_status(self, gid, sid):
|
||||||
"""Check and return the connection status."""
|
"""Check and return the connection status."""
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
res = conn.connected()
|
res = conn.connected()
|
||||||
@ -769,7 +761,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
save_password = False
|
save_password = False
|
||||||
|
|
||||||
# Connect the Server
|
# Connect the Server
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
@ -902,7 +893,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
return bad_request(gettext("Server not found."))
|
return bad_request(gettext("Server not found."))
|
||||||
|
|
||||||
# Release Connection
|
# Release Connection
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
|
|
||||||
status = manager.release()
|
status = manager.release()
|
||||||
@ -923,7 +913,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
"""Reload the server configuration"""
|
"""Reload the server configuration"""
|
||||||
|
|
||||||
# Reload the server configurations
|
# Reload the server configurations
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
@ -958,7 +947,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
try:
|
try:
|
||||||
data = request.form
|
data = request.form
|
||||||
restore_point_name = data['value'] if data else None
|
restore_point_name = data['value'] if data else None
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
@ -1033,7 +1021,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
if user is None:
|
if user is None:
|
||||||
return unauthorized(gettext("Unauthorized request."))
|
return unauthorized(gettext("Unauthorized request."))
|
||||||
|
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
@ -1100,7 +1087,6 @@ class ServerNode(PGChildNodeView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pgadmin.utils.driver import get_driver
|
|
||||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||||
conn = manager.connection()
|
conn = manager.connection()
|
||||||
|
|
||||||
|
@ -1721,6 +1721,17 @@ class Driver(BaseDriver):
|
|||||||
"""
|
"""
|
||||||
return self.connection_manager(sid).release(database, conn_id)
|
return self.connection_manager(sid).release(database, conn_id)
|
||||||
|
|
||||||
|
def delete_manager(self, sid):
|
||||||
|
"""
|
||||||
|
Delete manager for given server id.
|
||||||
|
"""
|
||||||
|
manager = self.connection_manager(sid)
|
||||||
|
if manager is not None:
|
||||||
|
manager.release()
|
||||||
|
if session['_id'] in self.managers and \
|
||||||
|
str(sid) in self.managers[session['_id']]:
|
||||||
|
del self.managers[session['_id']][str(sid)]
|
||||||
|
|
||||||
def gc(self):
|
def gc(self):
|
||||||
"""
|
"""
|
||||||
Release the connections for the sessions, which have not pinged the
|
Release the connections for the sessions, which have not pinged the
|
||||||
|
Loading…
Reference in New Issue
Block a user