Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing][grass] Make a copy of the parameters dict before doing g…
…rass modifications

Since grass algorithms modify the parameters dictionary, we need to ensure
that they do this only a copy of the dict (and not a shallow copy). Otherwise
the parameter values included in the history log are the internally
modified values, not the original user-set ones
  • Loading branch information
nyalldawson committed Jul 24, 2018
1 parent 996c9a8 commit fed345b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -363,14 +363,17 @@ def grabDefaultGrassParameters(self, parameters, context):
self.GRASS_REGION_ALIGN_TO_RESOLUTION,
context)

def processAlgorithm(self, parameters, context, feedback):
def processAlgorithm(self, original_parameters, context, feedback):
if isWindows():
path = Grass7Utils.grassPath()
if path == '':
raise QgsProcessingException(
self.tr('GRASS GIS 7 folder is not configured. Please '
'configure it before running GRASS GIS 7 algorithms.'))

# make a copy of the original parameters dictionary - it gets modified by grass algorithms
parameters = {k: v for k, v in original_parameters.items()}

# Create brand new commands lists
self.commands = []
self.outputCommands = []
Expand Down Expand Up @@ -987,8 +990,9 @@ def canExecute(self):
return not message, message

def checkParameterValues(self, parameters, context):
grass_parameters = {k: v for k, v in parameters.items()}
if self.module:
if hasattr(self.module, 'checkParameterValuesBeforeExecuting'):
func = getattr(self.module, 'checkParameterValuesBeforeExecuting')
return func(self, parameters, context)
return super(Grass7Algorithm, self).checkParameterValues(parameters, context)
return func(self, grass_parameters, context)
return super().checkParameterValues(grass_parameters, context)

0 comments on commit fed345b

Please sign in to comment.