From 377e5e23ecca0f7491843dfc8cabe59b10c5761c Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 2 Oct 2020 17:52:02 +0200 Subject: [PATCH] Fix broken layer dependencies for old projects Fixes #39025 by skipping the broken relations detection for widget configuations that were created before weak relations were introduced and add an extra check for projects that were created before recent fixes in 3.15 with commit 7e8c7b3d0e09 --- src/app/qgisapp.cpp | 7 ++++++- .../fieldformatter/qgsrelationreferencefieldformatter.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 750ec8bbc9e..1bf47711997 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -2249,7 +2249,7 @@ const QList QgisApp::findBrokenLayerDependencies( QgsVectorLa if ( found ) { - // Make sure we don't add it twice + // Make sure we don't add it twice if it was already added by the form widgets check bool refFound = false; for ( const QgsVectorLayerRef &otherRef : qgis::as_const( brokenDependencies ) ) { @@ -2277,6 +2277,11 @@ void QgisApp::resolveVectorLayerDependencies( QgsVectorLayer *vl, QgsMapLayer::S const auto constDependencies { findBrokenLayerDependencies( vl, categories ) }; for ( const QgsVectorLayerRef &dependency : constDependencies ) { + // Temporary check for projects that were created before commit 7e8c7b3d0e094737336ff4834ea2af625d2921bf + if ( QgsProject::instance()->mapLayer( dependency.layerId ) ) + { + continue; + } // try to aggressively resolve the broken dependencies bool loaded = false; const QString providerName { vl->dataProvider()->name() }; diff --git a/src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp b/src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp index c6e03b56cba..e6efa7f5a12 100644 --- a/src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp +++ b/src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp @@ -176,6 +176,13 @@ QVariant QgsRelationReferenceFieldFormatter::createCache( QgsVectorLayer *layer, QList QgsRelationReferenceFieldFormatter::layerDependencies( const QVariantMap &config ) const { + // Old projects, create before the weak relations were introduced and stored with the + // widget configuration do not have the referenced layer details but only the "Relation" id, + // for these projects automatic loading of broken references is not supported. + if ( config.value( QStringLiteral( "ReferencedLayerId" ) ).toString().isEmpty() ) + { + return {}; + } const QList result {{ QgsVectorLayerRef(