Skip to content

Commit 698befa

Browse files
committed
[gpkg] Add test for gpkg subsetstring don't unlock mutex twice
I wanted to add the test for gpkg subsetstring even if it was not bugged, while testing that, I hit an assert in Qt core that pointed me to double unlocked locks.
1 parent cd0559d commit 698befa

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5258,7 +5258,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
52585258
if ( !hLayer )
52595259
{
52605260
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database." );
5261-
mutex->unlock();
52625261
return false;
52635262
}
52645263
bool ok = true;
@@ -5322,7 +5321,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
53225321
if ( !ok )
53235322
{
53245323
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database." );
5325-
mutex->unlock();
53265324
return false;
53275325
}
53285326
}
@@ -5379,7 +5377,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
53795377
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No ) )
53805378
{
53815379
errCause = QObject::tr( "Operation aborted" );
5382-
mutex->unlock();
53835380
return false;
53845381
}
53855382
bNew = false;
@@ -5431,8 +5428,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
54315428
else
54325429
bFeatureOK = OGR_L_SetFeature( hLayer, hFeature.get() ) == OGRERR_NONE;
54335430

5434-
mutex->unlock();
5435-
54365431
if ( !bFeatureOK )
54375432
{
54385433
QgsMessageLog::logMessage( QObject::tr( "Error updating style" ) );

tests/src/python/test_provider_ogr_gpkg.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
__revision__ = '$Format:%H$'
1414

1515
import os
16+
import re
1617
import shutil
1718
import sys
1819
import tempfile
@@ -860,6 +861,42 @@ def testSubSetStringEditable_bug17795(self):
860861
vl.setSubsetString('')
861862
self.assertTrue(vl.dataProvider().capabilities() & isEditable)
862863

864+
def testSubsetStringExtent_bug17863(self):
865+
"""Check that the extent is correct when applied in the ctor and when
866+
modified after a subset string is set """
867+
868+
def _lessdigits(s):
869+
return re.sub(r'(\d+\.\d{3})\d+', r'\1', s)
870+
871+
testPath = TEST_DATA_DIR + '/' + 'provider/bug_17795.gpkg|layername=bug_17795'
872+
subSetString = '"name" = \'int\''
873+
subSet = '|layername=bug_17795|subset=%s' % subSetString
874+
875+
# unfiltered
876+
vl = QgsVectorLayer(testPath, 'test', 'ogr')
877+
self.assertTrue(vl.isValid())
878+
unfiltered_extent = _lessdigits(vl.extent().toString())
879+
del(vl)
880+
881+
# filter after construction ...
882+
subSet_vl2 = QgsVectorLayer(testPath, 'test', 'ogr')
883+
self.assertEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
884+
# ... apply filter now!
885+
subSet_vl2.setSubsetString(subSetString)
886+
self.assertEqual(subSet_vl2.subsetString(), subSetString)
887+
self.assertNotEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
888+
filtered_extent = _lessdigits(subSet_vl2.extent().toString())
889+
del(subSet_vl2)
890+
891+
# filtered in constructor
892+
subSet_vl = QgsVectorLayer(testPath + subSet, 'subset_test', 'ogr')
893+
self.assertEqual(subSet_vl.subsetString(), subSetString)
894+
self.assertTrue(subSet_vl.isValid())
895+
896+
# This was failing in bug 17863
897+
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
898+
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)
899+
863900

864901
if __name__ == '__main__':
865902
unittest.main()
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)