Skip to content

Commit

Permalink
fix crash when a sink parameter definition is missing in a processing…
Browse files Browse the repository at this point in the history
… alg (#35074)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
qgis-bot and github-actions[bot] committed Mar 14, 2020
1 parent 14032d3 commit 835bf12
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
Expand Up @@ -622,7 +622,7 @@ Evaluates the parameter with matching ``name`` to a static boolean value.
%End

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

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

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

:raises :: py:class:`QgsProcessingException`
%End

QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
Expand Down
Expand Up @@ -680,7 +680,7 @@ This function creates a new object and the caller takes responsibility for delet

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

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

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

:raises :: py:class:`QgsProcessingException`

.. versionadded:: 3.4
%End

Expand Down
4 changes: 2 additions & 2 deletions scripts/sipify.pl
Expand Up @@ -1206,8 +1206,8 @@ sub detect_non_method_member{
# multiline definition (parenthesis left open)
if ( $MULTILINE_DEFINITION != MULTILINE_NO ){
dbg_info("on multiline");
# https://regex101.com/r/DN01iM/2
if ( $LINE =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
# https://regex101.com/r/DN01iM/4
if ( $LINE =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)([^()](throw\([^()]+\))?)*$/){
dbg_info("ending multiline");
# remove potential following body
if ( $MULTILINE_DEFINITION != MULTILINE_CONDITIONAL_STATEMENT && $LINE !~ m/(\{.*\}|;)\s*(\/\/.*)?$/ ){
Expand Down
9 changes: 8 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -599,7 +599,14 @@ bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters,

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
{
return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
try
{
return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
}
catch ( QgsProcessingException )
{
throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
}
}

QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
Expand Down
4 changes: 3 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -627,9 +627,11 @@ class CORE_EXPORT QgsProcessingAlgorithm
* to the sink, e.g. via calling QgsProcessingUtils::mapLayerFromString().
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*
* \throws QgsProcessingException
*/
QgsFeatureSink *parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT,
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = nullptr ) const SIP_FACTORY;
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags = nullptr ) const SIP_THROW( QgsProcessingException ) SIP_FACTORY;

/**
* Evaluates the parameter with matching \a name to a feature source.
Expand Down
4 changes: 4 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -431,6 +431,10 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar
return nullptr;
}
// fall back to default
if ( !definition )
{
throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
}
dest = definition->defaultValue().toString();
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingparameters.h
Expand Up @@ -753,12 +753,12 @@ class CORE_EXPORT QgsProcessingParameters
* to the sink, e.g. via calling QgsProcessingUtils::mapLayerFromString().
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*
* \throws QgsProcessingException
* \since QGIS 3.4
*/
static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value,
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_FACTORY;
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_THROW( QgsProcessingException ) SIP_FACTORY;

/**
* Evaluates the parameter with matching \a definition to a feature source.
Expand Down

0 comments on commit 835bf12

Please sign in to comment.