Bug 2258467

Summary: PyQt6 and PyQt5 ignore "dir" argument in QFileDialog.getOpenFileName
Product: [Fedora] Fedora Reporter: Michael Clerx <Michael.Clerx>
Component: python-pyqt6Assignee: Onuralp SEZER <thunderbirdtr>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: 38CC: epel-packagers-sig, jonathan, kde-sig, manisandro, thunderbirdtr
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-05-27 13:29:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Michael Clerx 2024-01-15 14:20:32 UTC
Since some time in 2021 (https://bugreports.qt.io/browse/QTBUG-92961, https://stackoverflow.com/questions/75878424) I've been running into an issue where QFileDialog.getOpenFileName ignores the "dir" argument (recently renamed "directory"):

    QtWidgets.QFileDialog.getOpenFileName(
        self,
        'Open file',
        '/home/michael/some/path',
    )

This is supposed to create an open file dialog initialised at "/home/michael/some/path", but at some point (around Fedora 33?) this stopped working.

The same functionality for getSaveFileName() works as expected.

I've only just noticed that the bug disappears if I install PyQt5 or PyQt6 into a virtual environment using pip, even when I specify the exact same versions that DNF installs. So it looks like this is an issue with the packaged version only. Because it's been present for quite a while now, I can't pinpoint where it was introduced, but I have seen the same bug on multiple devices, and in fresh installs of a variety of versions.

A script to reproduce:

#!/usr/bin/env python3
import sys
from PyQt6 import QtWidgets
#from PyQt5 import QtWidgets

# Change this to a valid & accessible path (other than your home)
path = '/home/michael/a/path/that/definitely/exists'

class App(QtWidgets.QMainWindow):
    def __init__(self, path):
        super().__init__()
        self.setWindowTitle('Qt bug test')
        QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', path)[0]
        sys.exit()

if __name__ == '__main__':
    a = QtWidgets.QApplication([])
    a.lastWindowClosed.connect(a.quit)
    app = App(path)
    app.show()
    sys.exit(a.exec())


Reproducible: Always

Steps to Reproduce:
1. Change the `path` variable to an existing path, which you can access, but which isn't your home directory
2. Run the example code using PyQt5 or PyQt6 installed through DNF

Actual Results:  
An open file dialog appears showing the contents of your home directory

Expected Results:  
An open file dialog appears showing the contents of `path`

Comment 1 Sandro Mani 2024-02-16 22:25:05 UTC
Cannot reproduce this with either python3-pyqt6-6.6.1-4.fc40 or python3-qt5-5.15.10-4.fc40. Can you reproduce this with a clean install (i.e. in a virtualbox)?

Comment 2 Michael Clerx 2024-02-20 19:49:30 UTC
I cannot reproduce this in a clean install of Fedora 39.
But I can reproduce it in a clean install of 38, and then all the way back to 32 (but not in 31).

I'm glad it works again in 39, but might be good to have a test or something to make sure it doesn't reoccur in newer versions?

Comment 3 Sandro Mani 2024-02-28 13:43:40 UTC
> But I can reproduce it in a clean install of 38, and then all the way back to 32 (but not in 31).

Clean and up-to-date F38?

Comment 4 Michael Clerx 2024-02-28 13:59:40 UTC
Yes I can recreate the problem with

1. Clean install of F38
2. dnf install python3-pyqt5 (or 6)

and with

1. Clean install of F38
2. dnf install python3-pyqt5 (or 6)
3. dnf update -y

Comment 5 Sandro Mani 2024-05-27 13:29:10 UTC
F38 ist EOL.