From f7fc37a4223a26043da2718bb5477fcb5119ec78 Mon Sep 17 00:00:00 2001 From: Jacky Volpes Date: Thu, 19 Dec 2024 18:20:04 +0100 Subject: [PATCH 1/2] fix boolean filtering in qgis expressions with WFS layers 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 | 31 +++++++++++++++++++ 2 files changed, 33 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..18b8bb6389a2 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,33 @@ 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() From 4c70a7f0d28026aadac8a87c6fc0db2a4624d579 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:46:03 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/python/test_provider_wfs.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/src/python/test_provider_wfs.py b/tests/src/python/test_provider_wfs.py index 18b8bb6389a2..bc385e4f3880 100644 --- a/tests/src/python/test_provider_wfs.py +++ b/tests/src/python/test_provider_wfs.py @@ -6417,28 +6417,26 @@ def testFilteredFeatureRequests(self): self.assertEqual(other_feat["name"], "Xxx") qgis_feat = next( - vl.getFeatures(QgsFeatureRequest(QgsExpression("\"verified\" is true"))) + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" is true'))) ) other_feat = next( - vl.getFeatures(QgsFeatureRequest(QgsExpression("\"verified\" is false"))) + 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\""))) - ) + qgis_feat = next(vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified"')))) other_feat = next( - vl.getFeatures(QgsFeatureRequest(QgsExpression("not \"verified\""))) + 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"))) + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" = true'))) ) other_feat = next( - vl.getFeatures(QgsFeatureRequest(QgsExpression("\"verified\" = false"))) + vl.getFeatures(QgsFeatureRequest(QgsExpression('"verified" = false'))) ) self.assertEqual(qgis_feat["name"], "Xxx") self.assertEqual(other_feat["name"], "qgis")