code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
225 stars 82 forks source link

AttributeError: 'QVariant' object has no attribute 'toString' #44

Closed thierry-FreeBSD closed 5 years ago

thierry-FreeBSD commented 5 years ago

Trying v5.3.3, code_saturne gui produces the following error:

  File "/usr/local/bin/code_saturne", line 76, in <module>
    retcode = cs.execute()
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 91, in execute
    return self.commands[command](options)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 150, in gui
    return cs_gui.main(options, self.package)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_gui.py", line 196, in main
    mv = MainView(cmd_package = pkg, cmd_case = case)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/MainView.py", line 1346, in __init__
    self.Browser = BrowserView()
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/BrowserView.py", line 385, in __init__
    self.model = TreeModel(from_qvariant(to_qvariant(tree), to_text_string))
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/QtPage.py", line 144, in from_qvariant
    return convfunc(qobj.toString())
AttributeError: 'QVariant' object has no attribute 'toString'

Am I missing something? Note: this is on FreeBSD.

YvanFournier commented 5 years ago

Hello,

Which versions of Pyton and Qt are you using ? It seems you are in the PYQT_AP1 path, which should match PyQt4, but is not expected with PyQt5 (whether Python 2 or 3). If this is the case, it means the detection/setting of the API variant works differently on FreeBsd than on the Linux machines we have tested it on, and fails here.

Also, did you observe this error on v3.3.2 or other versions ? Checking the Git logs, I see no change in that part of the code since v3.3.2 which would be obviously related to this, though I may have missed something.

Based on your actual tool versions, I can suggest different tests/variants to try to solve this issue.

thierry-FreeBSD commented 5 years ago

On FreeBSD, everything depending on Qt4 has been removed, and the default Python version is 2.7 (but 3.6 is available when needed). I'm using py27-qt5* versions 5.12.1.

paspro commented 5 years ago

I have the exact same problem on Ubuntu with Python 2.7.16 and PyQt5 5.12.1

YvanFournier commented 5 years ago

So this seems to be a Python2+Qt5 issue.

We have tested mostly with Python2+Qt4 and Python3+Qt5, though I did run some Python2+Qt5 some time ago.

I do not currently have access to such a combination (the machine I had VM's on died, its replacement is not yet set up).

Could you try replacing bin/sc_gui.py with the version from the master branch ? A change in this file (trying to force the Sip API to API2) which I had thought a bit risky for v6.0 might actually solve the issue. It it works, I'll simply cherry-pick that part of the matching commit in v6.0.

thierry-FreeBSD commented 5 years ago

Sorry, I get the same message with the latest bin/cs_gui.py:

$ Traceback (most recent call last):
  File "/usr/local/bin/code_saturne", line 76, in <module>
    retcode = cs.execute()
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 91, in execute
    return self.commands[command](options)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 150, in gui
    return cs_gui.main(options, self.package)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_gui.py", line 199, in main
    mv = MainView(cmd_package = pkg, cmd_case = case)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/MainView.py", line 1346, in __init__
    self.Browser = BrowserView()
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/BrowserView.py", line 385, in __init__
    self.model = TreeModel(from_qvariant(to_qvariant(tree), to_text_string))
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/QtPage.py", line 144, in from_qvariant
    return convfunc(qobj.toString())
AttributeError: 'QVariant' object has no attribute 'toString'

[1]  + exit 1     code_saturne gui
YvanFournier commented 5 years ago

Ok, it seems we are stuck in the API1 mode, even though we tried to force API2 (which usually happens only when API1 is forced first during the same program execution...)

I'll need to check things as I had anticipated removing API1 support on the master branch (which will impact v6.1 next fall).

In the meantime, to confirm this, could you edit gui/Base/QtPage.py, and replace line 121:

    if QT_API == "PYQT4":

With:

    if sys.version_info[0] == 2:

Our test for Sip is based on the Qt API, maybe it should be based on the Python version...

thierry-FreeBSD commented 5 years ago

With this patch, we get a different message:


$ Traceback (most recent call last):
  File "/usr/local/bin/code_saturne", line 76, in <module>
    retcode = cs.execute()
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 91, in execute
    return self.commands[command](options)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_script.py", line 150, in gui
    return cs_gui.main(options, self.package)
  File "/usr/local/lib/python2.7/site-packages/code_saturne/cs_gui.py", line 195, in main
    from code_saturne.Base.MainView import MainView
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/MainView.py", line 78, in <module>
    from code_saturne.Base.BrowserView import BrowserView
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/BrowserView.py", line 50, in <module>
    from code_saturne.Base.QtPage import to_qvariant, from_qvariant, to_text_string
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/QtPage.py", line 123, in <module>
    PYQT_API_1 = sip.getapi('QVariant') == 1
ValueError: unknown API 'QVariant'

[1]  + exit 1     code_saturne gui
YvanFournier commented 5 years ago

This sort of issue is probably why we do not have more robust tests.. The code should not exit when we are running this test inside a "try... except..." construct, but does. So we need to work around a Sip bug...

A solution would be to run more tests at the configure stage, but I am still not sure how PyQt and Sip are behaving here...

A last test would be to ignore detection and assme API2 by replacing: PYQT_API_1 = sip.getapi('QVariant') == 1 with: PYQT_API_1 = False

(or remove the test altogether as it is already placed before).

This is more similar to what is done in the "master" branch, so could be the solution. Although if it works, I am comfortable merging to v6.0 (in beta stage, nearing rc status), but would need to think a bit more for 5.3 (so upgrades don't break existing working cases).

YvanFournier commented 5 years ago

Another simpler possible cause may be that the QT_API environment variable might be set incorrectly (if this is the case, we can solve that later).

What happens if you simply export QT_API=PYQT5 before running the GUI ?

thierry-FreeBSD commented 5 years ago

A last test would be to ignore detection and assme API2 by replacing: PYQT_API_1 = sip.getapi('QVariant') == 1 with: PYQT_API_1 = False

I tried the hereunder patch, but since it is enclosed in if QT_API == "PYQT4", that does not change anything:

--- gui/Base/QtPage.py.orig 2019-05-07 12:03:47 UTC
+++ gui/Base/QtPage.py
@@ -120,7 +120,7 @@ if os.environ.get('QT_API', 'pyqt') == 'pyqt':
     import sip
     if QT_API == "PYQT4":
         try:
-            PYQT_API_1 = sip.getapi('QVariant') == 1
+            PYQT_API_1 = False
         except AttributeError:
             PYQT_API_1 = True
thierry-FreeBSD commented 5 years ago

What happens if you simply export QT_API=PYQT5 before running the GUI ?

This one does the trick!

thierry-FreeBSD commented 5 years ago

Hmm, sorry... The first screen is displayed, but when one tries to do something, it aborts quickly. E.g.:

$ Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/code_saturne/Base/MainView.py", line 1181, in displayNewPage
    self.tr('OK'))
TypeError: information(QWidget, str, str, buttons: Union[QMessageBox.StandardButtons, QMessageBox.StandardButton] = QMessageBox.Ok, defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton): argument 4 has unexpected type 'unicode'
QSocketNotifier: Invalid socket 11 and type 'Read', disabling...
QSocketNotifier: Invalid socket 13 and type 'Read', disabling...
YvanFournier commented 5 years ago

Are all the Qt4 and PyQt4 libraries removed from the system ? Just in case, adding QT_SELECT=5 to the configure command could help if we have both versions installed.

But it really seems as if in your system there are incomplete remnants of Qt4, or I do not understand what is going on yet.

thierry-FreeBSD commented 5 years ago

Everything related to Qt4 has been removed. Anyway, I tried to pass QT_SELECT=5, but there is no effect...

YvanFournier commented 5 years ago

OK, I guess I will need to generate a small "standalone" test case for this, unless I can reproduce it under a VM I have access to. I probably won't have access to a relevant machine before 2 weeks, I'll try the standalone test before that.

Any additional feedback or idea in the meantime is of course welcome.

thierry-FreeBSD commented 5 years ago

Good news: everything is fine with Python 3.6!

YvanFournier commented 5 years ago

On my side, I re-tested on Arch Linux with both Python 2 and 3, and did not reproduce the issue, even when using python3's pyuic5 instead of python2-pyuic, which can be forced on the configure line, but might not be selected correctly based on priority when both are present (I suspected this could explain the issue).

I'm tempted to close the issue, as things are OK with Python 3, and Python 2 is on the way out, but I"ll wait a bit longer to test on Ubuntu if I have time or wait for additional feedback.

YvanFournier commented 5 years ago

Also tested on Ubuntu 18.04, issue not reproduced.