Bug report #15505

Wrong result returned by layer.getFeatures(request) in editing mode when setting limit on request

Added by Casper Børgesen about 8 years ago. Updated about 7 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Unknown
Affected QGIS version:2.16.1 Regression?:No
Operating System:windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:23429

Description

I'll describe this as steps:

  1. Create a SHAPE layer with 4 points on a line (so its easy to reference them by number).
  2. Delete the third point and stay in editing mode.
  3. Make the following python calls:

>>> req = QgsFeatureRequest()
>>> req = req.setLimit(3)
>>> len(list(iface.mapCanvas().currentLayer().getFeatures(req)))
2

I would expect the above getFeatures request to return 3 features, since that should be the number of features left and at the same time within the limit defined by the request.

Based on a brief discussion on the mailing list, Nyall proposes the following:


I'd say something like this could work. In QgsVectorLayerFeatureIterator:
- take the feature request limit for mProviderRequest
- if deleted features are present in the edit buffer, add the number of deleted features to the limit in mProviderRequest
- if changed feature attributes are present, and the request is an expression based request, add the number of changed features to the limit (could be smarter here and check which attributes are required by the filter + which have changed)
- if geometry changes are present and a filter rect is in place then add the number of geometry changes to the limit

That would still gain us most of the benefits of feature limits + handle this case, and the only penalty is present when the bug would otherwise show itself.

The bug is also present in master (d3882d5).

Associated revisions

Revision 2665eb50
Added by Nyall Dawson about 8 years ago

Correctly handle edit buffer when using request with limit (fix #15505)

Revision 89e69045
Added by Nyall Dawson about 8 years ago

Correctly handle edit buffer when using request with limit (fix #15505)

(cherry-picked from 2665eb50a69220324f4a6d045e8eba6601760dd3)

Revision e79f2b91
Added by Nyall Dawson about 8 years ago

Correctly handle edit buffer when using request with limit (fix #15505)

(cherry-picked from 2665eb50a69220324f4a6d045e8eba6601760dd3)

History

#1 Updated by Nyall Dawson about 8 years ago

  • Status changed from Open to Closed

#2 Updated by Jürgen Fischer about 7 years ago

  • Category set to Unknown

Also available in: Atom PDF