Skip to content

Commit

Permalink
Merge pull request #58091 from qgis/backport-58080-to-release-3_38
Browse files Browse the repository at this point in the history
[Backport release-3_38] [grass] Ensure vector inputs respect layer filters
  • Loading branch information
alexbruy authored Jul 15, 2024
2 parents adbaa5f + 15dbc6b commit 56bc3c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/plugins/grassprovider/grass_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,10 @@ def loadVectorLayer(self, name, layer,
os.path.normpath(file_path),
' layer="{}"'.format(layer_name) if layer_name else '',
destFilename)
if layer.subsetString():
escaped_subset = layer.subsetString().replace('"', '\\"')
command += f' where="{escaped_subset}"'

self.commands.append(command)

def exportVectorLayerFromParameter(self, name, parameters, context, layer=None, nocats=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ def get_command(alg):
alg.loadVectorLayer('test_layer', vl, context, external=True)
self.assertEqual(get_command(alg), 'v.external input="testdata/pol.gpkg" output="###" --overwrite -o')

# layer with filter
vl = QgsVectorLayer(source + '|layername=pol3')
self.assertTrue(vl.isValid())
vl.setSubsetString('"field"=\'value\'')
alg.loadVectorLayer('test_layer', vl, context, external=False)
self.assertEqual(get_command(alg), 'v.in.ogr min_area=None snap=None input="testdata/pol.gpkg" layer="pol3" output="###" --overwrite -o where="\\"field\\"=\'value\'"')
alg.loadVectorLayer('test_layer', vl, context, external=True)
self.assertEqual(get_command(alg), 'v.external input="testdata/pol.gpkg" layer="pol3" output="###" --overwrite -o where="\\"field\\"=\'value\'"')


if __name__ == '__main__':
nose2.main()

0 comments on commit 56bc3c9

Please sign in to comment.