Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_40] Fix crash when exporting vectors if field domain cannot be retrieved #59297

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,26 +928,33 @@ void QgsVectorFileWriter::init( QString vectorFileName,
// - if successful, note that we know that field domain (if it
// is shared by other fields)
// - assign its name to the new field.
std::unique_ptr<QgsFieldDomain> domain( sourceDatabaseProviderConnection->fieldDomain( domainName ) );
if ( domain )
try
{
OGRFieldDomainH hFieldDomain = QgsOgrUtils::convertFieldDomain( domain.get() );
if ( hFieldDomain )
std::unique_ptr<QgsFieldDomain> domain( sourceDatabaseProviderConnection->fieldDomain( domainName ) );
if ( domain )
{
char *pszFailureReason = nullptr;
if ( GDALDatasetAddFieldDomain( mDS.get(), hFieldDomain, &pszFailureReason ) )
OGRFieldDomainH hFieldDomain = QgsOgrUtils::convertFieldDomain( domain.get() );
if ( hFieldDomain )
{
existingDestDomainNames.insert( domainName );
canSetFieldDomainName = true;
char *pszFailureReason = nullptr;
if ( GDALDatasetAddFieldDomain( mDS.get(), hFieldDomain, &pszFailureReason ) )
{
existingDestDomainNames.insert( domainName );
canSetFieldDomainName = true;
}
else
{
QgsDebugError( QStringLiteral( "cannot create field domain: %1" ).arg( pszFailureReason ) );
}
CPLFree( pszFailureReason );
OGR_FldDomain_Destroy( hFieldDomain );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "cannot create field domain: %1" ).arg( pszFailureReason ), 2 );
}
CPLFree( pszFailureReason );
OGR_FldDomain_Destroy( hFieldDomain );
}
}
catch ( QgsProviderConnectionException & )
{
QgsDebugError( QStringLiteral( "Cannot retrieve field domain: %1" ).arg( domainName ) );
}
}
if ( canSetFieldDomainName )
{
Expand Down
Loading