From cb6daf6ed31dd9b274fa174ae93244ab44a4eaa9 Mon Sep 17 00:00:00 2001 From: Peter Petrik Date: Mon, 25 Sep 2023 15:43:46 +0200 Subject: [PATCH] fix crash with broken relations --- app/attributes/attributecontroller.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index d582a4781..b6999b3b2 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -223,7 +223,7 @@ void AttributeController::flatten( int fieldIndex = editorField->idx(); if ( fieldIndex < 0 || fieldIndex >= layer->fields().size() ) { - qDebug() << "Invalid fieldIndex for editorField!"; + CoreUtils::log( "Forms", QStringLiteral( "Invalid fieldIndex for editorField in layer %1" ).arg( layer->name() ) ); continue; } QgsField field = layer->fields().at( fieldIndex ); @@ -269,10 +269,17 @@ void AttributeController::flatten( QgsAttributeEditorRelation *relationField = static_cast( element ); QgsRelation associatedRelation = relationField->relation(); + bool isValid = associatedRelation.isValid(); + if ( !isValid ) + { + CoreUtils::log( "Relations", QStringLiteral( "Ignoring invalid relation in layer %1" ).arg( layer->name() ) ); + continue; + } + bool isNmRelation = layer->editFormConfig().widgetConfig( associatedRelation.id() )[QStringLiteral( "nm-rel" )].toBool(); if ( isNmRelation ) { - CoreUtils::log( "Relations", "Nm relations are not supported" ); + CoreUtils::log( "Relations", QStringLiteral( "Nm relations are not supported in layer %1" ).arg( layer->name() ) ); continue; }