Skip to content

Commit 14b80de

Browse files
authored
fix crash when a sink parameter definition is missing in a processing alg (qgis#34978)
1 parent 35d8b06 commit 14b80de

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ Evaluates the parameter with matching ``name`` to a static boolean value.
623623
%End
624624

625625
QgsFeatureSink *parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier /Out/,
626-
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = 0 ) const /Factory/;
626+
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = 0 ) const throw( QgsProcessingException ) /Factory/;
627627
%Docstring
628628
Evaluates the parameter with matching ``name`` to a feature sink.
629629

@@ -637,6 +637,8 @@ The ``destinationIdentifier`` argument will be set to a string which can be used
637637
to the sink, e.g. via calling :py:func:`QgsProcessingUtils.mapLayerFromString()`
638638

639639
This function creates a new object and the caller takes responsibility for deleting the returned object.
640+
641+
:raises :: py:class:`QgsProcessingException`
640642
%End
641643

642644
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;

python/core/auto_generated/processing/qgsprocessingparameters.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ This function creates a new object and the caller takes responsibility for delet
754754

755755
static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value,
756756
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
757-
QgsProcessingContext &context, QString &destinationIdentifier /Out/, QgsFeatureSink::SinkFlags sinkFlags = 0 ) /Factory/;
757+
QgsProcessingContext &context, QString &destinationIdentifier /Out/, QgsFeatureSink::SinkFlags sinkFlags = 0 ) throw( QgsProcessingException ) /Factory/;
758758
%Docstring
759759
Evaluates the parameter with matching ``definition`` and ``value`` to a feature sink.
760760

@@ -768,6 +768,8 @@ to the sink, e.g. via calling :py:func:`QgsProcessingUtils.mapLayerFromString()`
768768

769769
This function creates a new object and the caller takes responsibility for deleting the returned object.
770770

771+
:raises :: py:class:`QgsProcessingException`
772+
771773
.. versionadded:: 3.4
772774
%End
773775

scripts/sipify.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,8 @@ sub detect_non_method_member{
12101210
# multiline definition (parenthesis left open)
12111211
if ( $MULTILINE_DEFINITION != MULTILINE_NO ){
12121212
dbg_info("on multiline");
1213-
# https://regex101.com/r/DN01iM/2
1214-
if ( $LINE =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
1213+
# https://regex101.com/r/DN01iM/4
1214+
if ( $LINE =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)([^()](throw\([^()]+\))?)*$/){
12151215
dbg_info("ending multiline");
12161216
# remove potential following body
12171217
if ( $MULTILINE_DEFINITION != MULTILINE_CONDITIONAL_STATEMENT && $LINE !~ m/(\{.*\}|;)\s*(\/\/.*)?$/ ){

src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,14 @@ bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters,
599599

600600
QgsFeatureSink *QgsProcessingAlgorithm::parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, QgsFeatureSink::SinkFlags sinkFlags ) const
601601
{
602-
return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
602+
try
603+
{
604+
return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
605+
}
606+
catch ( QgsProcessingException )
607+
{
608+
throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
609+
}
603610
}
604611

605612
QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const

src/core/processing/qgsprocessingalgorithm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ class CORE_EXPORT QgsProcessingAlgorithm
628628
* to the sink, e.g. via calling QgsProcessingUtils::mapLayerFromString().
629629
*
630630
* This function creates a new object and the caller takes responsibility for deleting the returned object.
631+
*
632+
* \throws QgsProcessingException
631633
*/
632634
QgsFeatureSink *parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT,
633-
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = nullptr ) const SIP_FACTORY;
635+
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = nullptr ) const SIP_THROW( QgsProcessingException ) SIP_FACTORY;
634636

635637
/**
636638
* Evaluates the parameter with matching \a name to a feature source.

src/core/processing/qgsprocessingparameters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar
548548
return nullptr;
549549
}
550550
// fall back to default
551+
if ( !definition )
552+
{
553+
throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
554+
}
551555
dest = definition->defaultValue().toString();
552556
}
553557
else

src/core/processing/qgsprocessingparameters.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,12 +821,12 @@ class CORE_EXPORT QgsProcessingParameters
821821
* to the sink, e.g. via calling QgsProcessingUtils::mapLayerFromString().
822822
*
823823
* This function creates a new object and the caller takes responsibility for deleting the returned object.
824-
*
824+
* \throws QgsProcessingException
825825
* \since QGIS 3.4
826826
*/
827827
static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value,
828828
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
829-
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_FACTORY;
829+
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_THROW( QgsProcessingException ) SIP_FACTORY;
830830

831831
/**
832832
* Evaluates the parameter with matching \a definition to a feature source.

0 commit comments

Comments
 (0)