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

Crash digitizing a feature when transaction group is on (after save) #39265

Closed
elpaso opened this issue Oct 8, 2020 · 2 comments · Fixed by #39283
Closed

Crash digitizing a feature when transaction group is on (after save) #39265

elpaso opened this issue Oct 8, 2020 · 2 comments · Fixed by #39283
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority

Comments

@elpaso
Copy link
Contributor

elpaso commented Oct 8, 2020

To reproduce: use the project and data from in https://github.com/qgis/QGIS/files/5348327/test.zip

  1. Start editing
  2. Digitize a feature (you get the error from Layer X: Feature has too many attributes (expecting 5, received 7) when "Automatic Creation of Transaction Group" is enabled #39230 but that's completely unrelated and the feature is saved)
  3. Save the layer (but keep it in editing state) (under the hood the transaction is closed and set to nullptr)
  4. digitize another feature, the crash happens when you click ok in the form (because transaction is nullptr)

CC @rouault

@elpaso elpaso added Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption labels Oct 8, 2020
@elpaso elpaso changed the title Crash when digitizing a feature on GPKG when transaction group is on (after save) Crash digitizing a feature when transaction group is on (after save) Oct 9, 2020
@elpaso
Copy link
Contributor Author

elpaso commented Oct 9, 2020

Reproducible on PG and GPKG.

@elpaso
Copy link
Contributor Author

elpaso commented Oct 9, 2020

Test case to reproduce the issue:

    def testTransactionGroupCrash(self):
        """Test issue GH #39265"""

        project = QgsProject()
        project.setAutoTransaction(True)
        tmpfile = os.path.join(
            self.basetestpath, 'tempGeoPackageTransactionCrash.gpkg')
        ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
        lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint)
        lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString))

        f = ogr.Feature(lyr.GetLayerDefn())
        f.SetGeometry(ogr.CreateGeometryFromWkt('POINT (1 1)'))
        f.SetField('str_field', 'one')
        lyr.CreateFeature(f)

        del lyr
        del ds

        vl = QgsVectorLayer(tmpfile + '|layername=test', 'test', 'ogr')

        project.addMapLayers([vl])

        feature = next(vl.getFeatures())
        feature.setAttributes([None, 'two'])

        self.assertTrue(vl.startEditing())
        self.assertTrue(vl.addFeature(feature))

        # Save
        self.assertTrue(vl.commitChanges(False))

        # Now add another one
        feature.setAttributes([None, 'three'])
        self.assertTrue(vl.addFeature(feature))

@elpaso elpaso self-assigned this Oct 9, 2020
elpaso added a commit to elpaso/QGIS that referenced this issue Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant