From 33fc10e0c28b660823a4881f80ce8921665b8323 Mon Sep 17 00:00:00 2001 From: qgis-bot <58983587+qgis-bot@users.noreply.github.com> Date: Wed, 8 Jan 2025 03:24:22 +0100 Subject: [PATCH] [Backport release-3_40] Fix boolean filtering in QGIS expressions with WFS layers (#60076) PR #56369 introduced a regression for WFS layers, because stopping using 'false' and 'true' strings to compare with boolean fields in qgis expressions, and forcing to use the keywords false and true, it conflicted with the internal SQLite cache database of WFS layers. This PR fixes it by storing internal boolean in SQLite cache database in the right form compatible with QGIS internal functions (i.e. storing '0' and '1' strings instead of 'true' and 'false' strings). --- .../wfs/qgsbackgroundcachedshareddata.cpp | 2 ++ tests/src/python/test_provider_wfs.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/providers/wfs/qgsbackgroundcachedshareddata.cpp b/src/providers/wfs/qgsbackgroundcachedshareddata.cpp index 0c7f61b1b3d3..c04098821aa2 100644 --- a/src/providers/wfs/qgsbackgroundcachedshareddata.cpp +++ b/src/providers/wfs/qgsbackgroundcachedshareddata.cpp @@ -642,6 +642,8 @@ void QgsBackgroundCachedSharedData::serializeFeatures( QVector( v.userType() ), fieldType ) ) cachedFeature.setAttribute( idx, v ); else diff --git a/tests/src/python/test_provider_wfs.py b/tests/src/python/test_provider_wfs.py index 1fff943a9bbe..bc385e4f3880 100644 --- a/tests/src/python/test_provider_wfs.py +++ b/tests/src/python/test_provider_wfs.py @@ -6277,6 +6277,7 @@ def testFilteredFeatureRequests(self): + @@ -6313,6 +6314,7 @@ def testFilteredFeatureRequests(self): 177 Xxx + true @@ -6344,6 +6346,7 @@ def testFilteredFeatureRequests(self): 177 Xxx + true @@ -6367,6 +6370,7 @@ def testFilteredFeatureRequests(self): 5 qgis + false 0 @@ -6412,6 +6416,31 @@ def testFilteredFeatureRequests(self): self.assertEqual(qgis_feat["name"], "qgis") self.assertEqual(other_feat["name"], "Xxx") + qgis_feat = next( + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" is true'))) + ) + other_feat = next( + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" is false'))) + ) + self.assertEqual(qgis_feat["name"], "Xxx") + self.assertEqual(other_feat["name"], "qgis") + + qgis_feat = next(vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified"')))) + other_feat = next( + vl.getFeatures(QgsFeatureRequest(QgsExpression('not "verified"'))) + ) + self.assertEqual(qgis_feat["name"], "Xxx") + self.assertEqual(other_feat["name"], "qgis") + + qgis_feat = next( + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" = true'))) + ) + other_feat = next( + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" = false'))) + ) + self.assertEqual(qgis_feat["name"], "Xxx") + self.assertEqual(other_feat["name"], "qgis") + form_scope = QgsExpressionContextUtils.formScope(qgis_feat) form_exp = QgsExpression("current_value('name') = \"name\"") ctx = QgsExpressionContext()