Bug report #17678

QgsVectorLayer::updateFeature fails when currentFeature.hasGeometry() == 0

Added by Mark Johnson over 2 years ago. Updated over 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:Yes
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:25575

Description

In QgsVectorLayer::updateFeature, when updating a record that contains 2 geometries, after the record has been created with the first geometry,
the second cannot be updated with a valid geometry since the 'current' returns hasGeometry() == 0.

  QgsFeature currentFeature = getFeature( updatedFeature.id() );
  if ( currentFeature.isValid() )
  {
    QgsDebugMsg( QString( "feature %1 could not be retrieved" ).arg( updatedFeature.id() ) );
    if ( updatedFeature.hasGeometry() && currentFeature.hasGeometry() && !updatedFeature.geometry().isGeosEqual( currentFeature.geometry() ) )
    {
     ...
    }
  }

The check for && currentFeature.hasGeometry() should be removed
  • updating a NULL geometry with a valid new geometry should be allowed
The current QgsDebugMsg is also misleading, since currentFeature.isValid() is true
  • this is a leftover from changes made to return when the record could not be retrieved
  • this message should occur as the else of the isValid() statement.
  QgsFeature currentFeature = getFeature( updatedFeature.id() );
  if ( currentFeature.isValid() )
  {
    QgsDebugMsg( QString( "feature %1 could was retrieved updatedFeature.hasGeometry[%2] currentFeature.hasGeometry[%3]" ).arg( updatedFeature.id() ).arg(updatedFeature.hasGeometry()).arg(currentFeature.hasGeometry()) );
    if ( updatedFeature.hasGeometry() && !updatedFeature.geometry().isGeosEqual( currentFeature.geometry() ) )
    {
     ...
    }
  }
  else
  {
    QgsDebugMsg( QString( "feature %1 could not be retrieved" ).arg( updatedFeature.id() ) );
  }

Associated revisions

Revision 5ecb5603
Added by Nyall Dawson over 2 years ago

Fix QgsVectorLayer::updateFeature returns true when errors occur

Refs #17678

Revision 71cdb8cf
Added by Nyall Dawson over 2 years ago

Fix QgsVectorLayer::updateFeature cannot add geometry to feature
with no existing geometry

Fixes #17678

History

#1 Updated by Mark Johnson over 2 years ago

At present when !currentFeature.isValid(), false is not returned
  • so a 'return false* is also needed after the message

#2 Updated by Nyall Dawson over 2 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

#3 Updated by Giovanni Manghi over 2 years ago

  • Resolution set to fixed/implemented

Also available in: Atom PDF