File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -3623,7 +3623,13 @@ void QgsOgrProvider::open( OpenMode mode )
3623
3623
// check that the initial encoding setting is fit for this layer
3624
3624
setEncoding ( encoding () );
3625
3625
3626
- mValid = setSubsetString ( mSubsetString );
3626
+ // Ensure subset is set (setSubsetString does nothing if the passed sql subset string is equal to mSubsetString, which is the case when reloading the dataset)
3627
+ QString origSubsetString = mSubsetString ;
3628
+ mSubsetString = " " ;
3629
+ // Block signals to avoid endless recusion reloadData -> emit dataChanged -> reloadData
3630
+ blockSignals ( true );
3631
+ mValid = setSubsetString ( origSubsetString );
3632
+ blockSignals ( false );
3627
3633
if ( mValid )
3628
3634
{
3629
3635
if ( mode == OpenModeInitial )
Original file line number Diff line number Diff line change @@ -200,7 +200,10 @@ def testDefaultValues(self):
200
200
self .assertTrue (vl .dataProvider ().defaultValue (6 ).secsTo (QDateTime .currentDateTime ()) < 1 )
201
201
202
202
def testSubsetStringFids (self ):
203
- """ tests that feature ids are stable even if a subset string is set """
203
+ """
204
+ - tests that feature ids are stable even if a subset string is set
205
+ - tests that the subset string is correctly set on the ogr layer event when reloading the data source (issue #17122)
206
+ """
204
207
205
208
tmpfile = os .path .join (self .basetestpath , 'subsetStringFids.sqlite' )
206
209
ds = ogr .GetDriverByName ('SQLite' ).CreateDataSource (tmpfile )
@@ -242,6 +245,7 @@ def testSubsetStringFids(self):
242
245
243
246
vl = QgsVectorLayer (tmpfile + "|subset=type=2" , 'test' , 'ogr' )
244
247
self .assertTrue (vl .isValid ())
248
+ self .assertTrue (vl .fields ().at (0 ).name () == "orig_ogc_fid" )
245
249
246
250
req = QgsFeatureRequest ()
247
251
req .setFilterExpression ("value=16" )
@@ -250,6 +254,10 @@ def testSubsetStringFids(self):
250
254
self .assertTrue (it .nextFeature (f ))
251
255
self .assertTrue (f .id () == 5 )
252
256
257
+ # Check that subset string is correctly set on reload
258
+ vl .reload ()
259
+ self .assertTrue (vl .fields ().at (0 ).name () == "orig_ogc_fid" )
260
+
253
261
254
262
if __name__ == '__main__' :
255
263
unittest .main ()
You can’t perform that action at this time.
0 commit comments