[QGIS-Developer] Purpose and function of "referenced_columns" in Python expression functions?

Johannes Kröger (WhereGroup) johannes.kroeger at wheregroup.com
Mon Nov 22 05:41:07 PST 2021


Hi list,

https://docs.qgis.org/3.22/en/docs/user_manual/expressions/expression.html#function-editor 
mentions the optional keyword argument "referenced_columns" to the 
`@qgsfunction` decorator. It says

 > referenced_columns=[list]: An array of attribute names that are 
required to the function. Defaults to
 > [QgsFeatureRequest.ALL_ATTRIBUTES].

That, and examples where it is used in other people's code, led me to 
believe that the feature's attributes would not be accessible unless 
listed in that parameter or if the parameter was omitted (-> default 
value getting used -> default is all attributes).

The default code that gets inserted into the editor includes the 
decorator `@qgsfunction(args='auto', group='Custom', 
referenced_columns=[])` so I'd assume that I would not be able to use 
any attributes in the function.

In reality I can access them just fine though, e. g. `feature["name"]` 
if I had features with a "name" attribute and that default 
`referenced_columns=[]`.

I can even do so if I used `referenced_columns=["foo", "bar"]`! 
`feature["name"]` is still perfectly accessible.

Is this a bug or by design? If by design, what purpose does this 
parameter have?

Thanks
Hannes

-- 
Johannes Kröger / GIS-Entwickler/-Berater
WhereGroup GmbH
Eifelstraße 7
53119 Bonn
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroeger at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------

********************************************
Where2B Konferenz 2021
16. Dezember 2021
im Universitätsclub Bonn und online
https://where2b-conference.com/
********************************************

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xBF7B268A77C202D5.asc
Type: application/pgp-keys
Size: 2471 bytes
Desc: OpenPGP public key
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20211122/3af557ce/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20211122/3af557ce/attachment-0001.sig>


More information about the QGIS-Developer mailing list