diff --git a/.ci/test_blocklist_qt6.txt b/.ci/test_blocklist_qt6.txt index c1cb435c5b0b..c064728657ea 100644 --- a/.ci/test_blocklist_qt6.txt +++ b/.ci/test_blocklist_qt6.txt @@ -58,7 +58,6 @@ PyQgsVectorLayerEditBuffer PyQgsLayerDefinition PyQgsSettings PyQgsSettingsEntry -PyQgsServerApi PyQgsServerWMSGetFeatureInfo PyQgsServerWMSGetMap PyQgsServerAccessControlWFSTransactional diff --git a/python/PyQt6/server/server.sip.in b/python/PyQt6/server/server.sip.in index a32d92d1cb72..2032ffca677f 100644 --- a/python/PyQt6/server/server.sip.in +++ b/python/PyQt6/server/server.sip.in @@ -15,19 +15,30 @@ ${DEFAULTDOCSTRINGSIGNATURE} %Include server_auto.sip + %VirtualErrorHandler serverapi_badrequest_exception_handler - PyObject *type, *exception, *traceback, *pyStrException; + PyObject *type, *exception, *traceback; PyErr_Fetch(&type, &exception, &traceback); - pyStrException = PyObject_Str(exception); - Py_DECREF(pyStrException); + // check whether the object is already a unicode string + QString pyStrException; + if ( PyUnicode_Check( exception) ) + { + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( exception ) ); + } + else + { + PyObject* str = PyObject_Str( exception ); + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( str ) ); + Py_XDECREF( str ); + } SIP_RELEASE_GIL( sipGILState ); QString strException = "API bad request error"; - if ( pyStrException && PyUnicode_Check(pyStrException) ) + if ( !pyStrException.isEmpty() ) { - strException = QString::fromUtf8( PyUnicode_AsUTF8(pyStrException) ); + strException = pyStrException; } throw QgsServerApiBadRequestException( strException ); @@ -35,19 +46,30 @@ ${DEFAULTDOCSTRINGSIGNATURE} %VirtualErrorHandler server_exception_handler - PyObject *type, *exception, *traceback, *pyStrException; + PyObject *type, *exception, *traceback; PyErr_Fetch(&type, &exception, &traceback); - pyStrException = PyObject_Str(exception); - Py_DECREF(pyStrException); + // check whether the object is already a unicode string + QString pyStrException; + if ( PyUnicode_Check( exception) ) + { + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( exception ) ); + } + else + { + PyObject* str = PyObject_Str( exception ); + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( str ) ); + Py_XDECREF( str ); + } SIP_RELEASE_GIL( sipGILState ); QString strException = "Server internal error"; - if ( pyStrException && PyUnicode_Check(pyStrException) ) + if ( !pyStrException.isEmpty() ) { - strException = QString::fromUtf8( PyUnicode_AsUTF8(pyStrException) ); + strException = pyStrException; } throw QgsServerException( strException ); %End + diff --git a/python/server/server.sip.in b/python/server/server.sip.in index a32d92d1cb72..69491f1d2f07 100644 --- a/python/server/server.sip.in +++ b/python/server/server.sip.in @@ -16,18 +16,28 @@ ${DEFAULTDOCSTRINGSIGNATURE} %VirtualErrorHandler serverapi_badrequest_exception_handler - PyObject *type, *exception, *traceback, *pyStrException; + PyObject *type, *exception, *traceback; PyErr_Fetch(&type, &exception, &traceback); - pyStrException = PyObject_Str(exception); - Py_DECREF(pyStrException); + // check whether the object is already a unicode string + QString pyStrException; + if ( PyUnicode_Check( exception) ) + { + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( exception ) ); + } + else + { + PyObject* str = PyObject_Str( exception ); + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( str ) ); + Py_XDECREF( str ); + } SIP_RELEASE_GIL( sipGILState ); QString strException = "API bad request error"; - if ( pyStrException && PyUnicode_Check(pyStrException) ) + if ( !pyStrException.isEmpty() ) { - strException = QString::fromUtf8( PyUnicode_AsUTF8(pyStrException) ); + strException = pyStrException; } throw QgsServerApiBadRequestException( strException ); @@ -35,18 +45,28 @@ ${DEFAULTDOCSTRINGSIGNATURE} %VirtualErrorHandler server_exception_handler - PyObject *type, *exception, *traceback, *pyStrException; + PyObject *type, *exception, *traceback; PyErr_Fetch(&type, &exception, &traceback); - pyStrException = PyObject_Str(exception); - Py_DECREF(pyStrException); + // check whether the object is already a unicode string + QString pyStrException; + if ( PyUnicode_Check( exception) ) + { + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( exception ) ); + } + else + { + PyObject* str = PyObject_Str( exception ); + pyStrException = QString::fromUtf8( PyUnicode_AsUTF8( str ) ); + Py_XDECREF( str ); + } SIP_RELEASE_GIL( sipGILState ); QString strException = "Server internal error"; - if ( pyStrException && PyUnicode_Check(pyStrException) ) + if ( !pyStrException.isEmpty() ) { - strException = QString::fromUtf8( PyUnicode_AsUTF8(pyStrException) ); + strException = pyStrException; } throw QgsServerException( strException );