Skip to content

Commit

Permalink
More helpful aggregate expression errors in more situations
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 11, 2021
1 parent 826c6a7 commit 5a5b637
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -818,11 +818,15 @@ static QVariant fcnAggregateRelation( const QVariantList &values, const QgsExpre


QgsExpressionContext subContext( *context );
result = childLayer->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback() );
QString error;
result = childLayer->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback(), &error );

if ( !ok )
{
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1" ).arg( subExpression ) );
if ( !error.isEmpty() )
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1 (%2)" ).arg( subExpression, error ) );
else
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1" ).arg( subExpression ) );
return QVariant();
}

Expand Down Expand Up @@ -942,11 +946,15 @@ static QVariant fcnAggregateGeneric( QgsAggregateCalculator::Aggregate aggregate
QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subScope->setVariable( QStringLiteral( "parent" ), context->feature() );
subContext.appendScope( subScope );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback() );
QString error;
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback(), &error );

if ( !ok )
{
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1" ).arg( subExpression ) );
if ( !error.isEmpty() )
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1 (%2)" ).arg( subExpression, error ) );
else
parent->setEvalErrorString( QObject::tr( "Could not calculate aggregate for: %1" ).arg( subExpression ) );
return QVariant();
}

Expand Down

0 comments on commit 5a5b637

Please sign in to comment.