Bug report #17170
Refactor fields processing algorithm missing expression context when edited in a model
|Affected QGIS version:||2.18.13||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||25069|
The "refactor fields" algorithm allows to create new fields based on an expression.
While this works fine, when started as a separate algorithm from the processing toolbox, the same expressions fail, when edited the "refactor fields" parameters as part of a model. The expression builder always reports an expression that involves an attribute field as "invalid syntax" and thus the expression can't be applied.
Somehow, when editing a model, some expression (layer) context is missing. In the expression builder, all fields of the chosen layer are missing.
[processing] Allow QgsVectorLayerSelectedFeatureSource to
create expression context scopes
Allows algorithms which require the underlying layer scope
to operate correctly when running in selected features only
#4 Updated by Nyall Dawson about 5 years ago
This is quite tricky to fix, because inside the model designer algorithms which are part of the model do not have knowledge of the available fields which will be present in their inputs. i.e. all it usually knows is that the input will be some vector layer, not which one or what fields it will have.
There's certain circumstances when we could determine in the designer what fields are available, e.g. when a layer source is hardcoded into a model. We could also potentially see if any previous algorithm steps in the models have added fields which we can then be certain will exist at the later 'refactor fields' stage, and show just these guaranteed fields. But that's not straightforward to do!
I've tested here (on master) and Refactor Fields works ok for me if I enter an expression using hard coded field names. They just aren't shown in the expression widget, but the expression can still include these and the model works correctly.