Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QSqlDatabase through sshtunnel hanging when commands (e.g. db.tables()) are sent - PySide6
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase through sshtunnel hanging when commands (e.g. db.tables()) are sent - PySide6

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 261 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mfjord
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      friedemannkleint
      wrote on last edited by
      #2

      This is basically PYSIDE-1931 . The reason is so far unclear.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mfjord
        wrote on last edited by mfjord
        #3

        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

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote on last edited by
          #4

          It seems something in that Driver/SSL tunnel locks up with Python's Global Interpreter Lock.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved