[QGIS-Developer] Why is the processing method outputWkbType() called by QGIS outside of the algorithm

Nyall Dawson nyall.dawson at gmail.com
Thu Sep 9 16:14:39 PDT 2021


On Thu, 9 Sept 2021 at 23:35, C Hamilton <adenaculture at gmail.com> wrote:
>
> I updated a number of my Shape Tools plugin routines to QgsProcessingFeatureBasedAlgorithm. One of the methods is outputWkbType which returns the WKB type. For my algorithm that type is determined by parameters selected when the user runs the algorithm. The variable used to determine the output type was initialized when the user runs the algorithm. This worked fine with the LTR release, but I found that when the user clicks in the Locator service text area in QGIS 3.20, QGIS is querying all of the outputWkbType() processing methods and was causing an exception because I had not initialized the variable yet.
>
> I don't know what the output wkb type is going to be until the user runs the algorithm, so why is QGIS spuriously calling all the processing algorithm outputWkbType() methods in QGIS 3.20. Apparently, it also happens when "edit in place" is active. If this is truly how you intend this to operate, then it would be good to include a note in the API documentation that this method can be called by QGIS and to make sure it can return a valid entry by initializing any variables in initParameters(). If this behavior is a bug, let me know and I will put in a ticket.

It's used by the default implementation of
QgsProcessingFeatureBasedAlgorithm.supportInPlaceEdits() to determine
if the algorithm changes the geometry type of a layer (making it
incompatible with in place editing modes). If you re-implement
supportInPlaceEdits() for your algorithm subclasses then you can avoid
this unwanted call.

Nyall


More information about the QGIS-Developer mailing list