Bug report #18241

QgsVectorJoinInfo.setJoinFieldNamesSubset() wrong fields order

Added by Mario Baranzini over 6 years ago.

Status:Open
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:3.1(master) Regression?:No
Operating System:Archlinux, Ubuntu Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:26132

Description

By creating a join, via Python, if a subset of fields to be joined is defined, the joined fields will be in the same order as in the joined layer, but the values will be in the order of the list passed to setJoinFieldNamesSubset instead.

For example, by joining the 2 following layers

with this code

join = QgsVectorLayerJoinInfo()
join.setJoinLayer(layer_1)
join.setJoinFieldName('id')
join.setTargetFieldName('id')
join.setJoinFieldNamesSubset(['column_b', 'column_a'])
layer_2.addJoin(join)

I get the following result

where the data of the 2 fields are in different order compared to the name of the fields

I tested it on 2.18.11 on Archlinux and master on Ubuntu with the same result. Attached, the complete python code to test this example on QGIS 2.18 and QGIS 3.0

before_join.png (36.8 KB) Mario Baranzini, 2018-02-27 07:12 AM

test_qgis3.py Magnifier (1.76 KB) Mario Baranzini, 2018-02-27 07:12 AM

after_join.png (40.6 KB) Mario Baranzini, 2018-02-27 07:12 AM

test_qgis2.py Magnifier (1.75 KB) Mario Baranzini, 2018-02-27 07:12 AM

Also available in: Atom PDF