Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apsw returns bad strings in python3 (assertion « (((PyASCIIObject*)obj)->state.ready) » fails) #168

Closed
espadons opened this issue Aug 6, 2014 · 1 comment

Comments

@espadons
Copy link

espadons commented Aug 6, 2014

apsw 3.8.2-r1-1-ubuntu1
python3 3.4.0-0ubuntu2
python3-pyqt4 4.10.4+dfsg1-ubuntu1

the following code snippet fails with the message
python3: ../../../qpy/QtCore/qpycore_qstring.cpp :96 : QString qpycore_PyObject_AsQString(PyObject_): l'assertion « (((PyASCIIObject_)obj)->state.ready) » a échoué.

Code:

!/usr/bin/env python3

-- coding: utf-8 --

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import apsw

from Ui_test3 import Ui_Test3
class Test3Dialog(QMainWindow, Ui_Test3):
def init(self):
QMainWindow.init(self)
# Set up the user interface from Designer.
self.setupUi(self)
self.cx = apsw.Connection("/home/pm/.datamanager/data/datamanager.sqlite")
self.curseur=self.cx.cursor()
self.curseur.execute("SELECT DISTINCT projet FROM projets WHERE actif='True' ORDER BY projet;")
#projets=["{}".format(x[0]) for x in self.curseur.fetchall()]
projets=[x[0] for x in self.curseur.fetchall()]
self.projectBox.addItems(projets)

if name == "main":
import sys
app = QApplication(sys.argv)

#
test1 =Test3Dialog()
test1.show()
sys.exit(app.exec_())

If the statement projets=[x[0] for x in self.curseur.fetchall()]
is replaced by projets=["{}".format(x[0]) for x in self.curseur.fetchall()]

it runs ok

the "datamanager.sqlite database has been used for years in python2 without any pb.
the Ui_test3.py file is automatically generated by pyuic from a qt-designer file 👍

-- coding: utf-8 --

Form implementation generated from reading ui file '/home/pm/Apps3/datamanager/sources/test3.ui'

Created: Wed Aug 6 14:19:54 2014

by: PyQt4 UI code generator 4.10.4

WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_Test3(object):
def setupUi(self, Test3):
Test3.setObjectName(_fromUtf8("Test3"))
Test3.resize(156, 138)
self.centralwidget = QtGui.QWidget(Test3)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.projectBox = QtGui.QComboBox(self.centralwidget)
self.projectBox.setGeometry(QtCore.QRect(20, 20, 82, 31))
self.projectBox.setObjectName(_fromUtf8("projectBox"))
Test3.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(Test3)
self.menubar.setGeometry(QtCore.QRect(0, 0, 156, 25))
self.menubar.setObjectName(_fromUtf8("menubar"))
Test3.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(Test3)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
Test3.setStatusBar(self.statusbar)

    self.retranslateUi(Test3)
    QtCore.QMetaObject.connectSlotsByName(Test3)

def retranslateUi(self, Test3):
    Test3.setWindowTitle(_translate("Test3", "MainWindow", None))

if name == "main":
import sys
app = QtGui.QApplication(sys.argv)
Test3 = QtGui.QMainWindow()
ui = Ui_Test3()
ui.setupUi(Test3)
Test3.show()
sys.exit(app.exec_())

@rogerbinns
Copy link
Owner

Technically APSW is in the right. PEP 393 changed how the CPython API for strings worked so it could use different (and usually shorter) internal representations. A call to PyUnicode_READY is required to perform that internal work.

However PEP 393 guarantees 5 years of backwards compatibility. Other extensions that care about the internal representation should be calling PyUnicode_READY themselves to ensure the backwards compatibility on received strings, and PyQt has not done so. Strings coming from the core interpreter already have it, so the PyQt authors wouldn't have noticed.

APSW will do so itself at some point, but I need to do careful compatibility testing and benchmarking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants