open-cogsci/QOpenScienceFramework

Error in creating QLabel when comparing versions

smathot opened this issue · 5 comments

I received the following automated bug report. It seems to result from trying to create a QLabel from an int.

Traceback (most recent call last):
  File "[Anonymized OpenSesame folder]\lib\site-packages\QOpenScienceFramework\manager.py", line 380, in <lambda>
    callback, *args, **kwargs
  File "[Anonymized OpenSesame folder]\lib\site-packages\QOpenScienceFramework\manager.py", line 839, in __reply_finished
    callback(reply, *args, **kwargs)
  File "[Anonymized OpenSesame folder]\share\opensesame_extensions\OpenScienceFramework\OpenScienceFramework.py", line 1141, in __process_file_info
    self.compare_versions(data)
  File "[Anonymized OpenSesame folder]\share\opensesame_extensions\OpenScienceFramework\OpenScienceFramework.py", line 530, in compare_versions
    remote_version_info=remote_info,
  File "[Anonymized OpenSesame folder]\share\opensesame_extensions\OpenScienceFramework\OpenScienceFramework.py", line 210, in __init__
    self.__setup_ui()
  File "[Anonymized OpenSesame folder]\share\opensesame_extensions\OpenScienceFramework\OpenScienceFramework.py", line 264, in __setup_ui
    QtWidgets.QLabel(self.local_version_info['filesize']))
TypeError: arguments did not match any overloaded call:
  QLabel(QWidget parent=None, Qt.WindowFlags flags=0): argument 1 has unexpected type 'long'
  QLabel(QString, QWidget parent=None, Qt.WindowFlags flags=0): argument 1 has unexpected type 'long'

I see wat happens, the culprit is the line above:

# If filesize is given as int, humanize it to comprehensible notations
if type(self.local_version_info['filesize']) in [int]: #, long]: (no longer exists?)
    self.local_version_info['filesize'] = humanize.naturalsize(
        self.local_version_info['filesize'])
local_form_layout.addRow(_(u"Size:"),
    QtWidgets.QLabel(self.local_version_info['filesize']))

This looks like a compatibility issue between Python 2 and 3 again, in that the 'long' type no longer exists in Python 3 (every int is already a long). I did not expect file sizes to be so large that they would ever have to be stored in a long, so I didn't check for it. Apparently someone has such large files and that causes this crash in python 2.

I will change this to six's integer_types variable which compares it both for int and long in Python 2 and int in Python 3

if type(self.local_version_info['filesize']) in six.integer_types:

This should now always convert int/long filetypes to human readable strings.

I have just pushed these changes to Github. Do you have any large experiments at your disposal to test this? I only have them with sizes in the int range, and otherwise it will take ages to upload from my house with the limited upload speed I have here.

Will take a look. How large should this file be?

For 32-bit python that is a minumum size of 231-1 bytes (and you still use the 32-bit version to package OS on windows, right?, otherwise it is 263-1). You can also check the max integer size by looking up the value of sys.maxint. Any value higher than this will be stored as a long (in Python 2).

Just a sidenote: this is a problem of opensesame-extension-osf, not QOpenScienceFramework, so this issue is assigned in the wrong repo. No biggie though...

I looked at your patch and it's clearly correct. Let's close this issue and not bother the OSF with a > 2Gb upload!