QSqlDatabase through sshtunnel hanging when commands (e.g. db.tables()) are sent - PySide6
-
Hi, I have a PostgreSQL database on a remote server, that I am trying to access within my Qt application.
I have connected to it through PuTTY to confirm that exists, and have created a table within it so that it isn't empty, however when I try to connect to it through QSqlDatabase it is hanging indefinitely upon attempting to retrieve anything from the database. I am able to successfully create and open the connection, but running something such as db.tables() results in it simply never returning until I am ultimately forced to force kill the program.
The code I am running is as follows:
self.tunnel = sshtunnel.open_tunnel( ('server.local', 22), ssh_username = "<username>", ssh_password = "<password>", local_bind_address = ('localhost', 3333), remote_bind_address = ('localhost', 5432), ) self.tunnel.start() db = QSqlDatabase.addDatabase("QPSQL") db.setHostName("localhost") db.setUserName("<username>") db.setPassword("<password>") db.setPort(3333) db.setDatabaseName("<database_name>") ok = db.open() print(db.tables())
Everything works fine (as far as I am aware) up until the final line - the tunnel is created, the authentication is successful, the QSqlDatabase is created and opened, but as soon as I try to run any command such as db.tables(), or db.record(<table_name>) it simply hangs and never returns nor progresses past that line. I do not even get an error message.
As a further check I tried running
ssh -L 3333:localhost:5432 <username>@server.local
from the command line and could successfully access the remote server this way as well, so it isn't just through PuTTY, and from there was able to run psql commands to access the database as expected.I'm unsure whether this is to do with my implementation of the tunnel or of the QSqlDatabase but I would appreciate any thoughts or suggestions.
Thanks in advance
-
This is basically PYSIDE-1931 . The reason is so far unclear.
-
You're right - I had searched (I thought) fairly extensively for similar issues but had somehow not come across that. It is exactly the problem I have run into - unfortunate that there isn't really a solution, I'd hoped that it was a problem with my own code.
Thanks though, I appreciate the response (and the link)
Although I am running into the issue even before attempting to implement a QSqlTableModel, so it must be an underlying thing affecting the QSqlDatabase in general. I'll try adding a QSqlQueryModel as per suggestions in the bug report comments and see if that somehow bypasses the problem
-
It seems something in that Driver/SSL tunnel locks up with Python's Global Interpreter Lock.