In QGIS 3.34.5 I have a vector layer in QGIS with a large amount of attributes.
I want to generate labels that only show relevant attributes. To do that, I define a PyQGIS function that takes a feature, looks at all attributes and stores the relevant ones in a dict.
Next, I convert the dict to a string with each key, value pair on a separate line.
This works well with a hardcoded dict (to just test the principle):
This also works well with the actual generated dict, storing the result in a virtual field rather than directly displaying in a label (as I cannot modify the layer source data).
It also works well inside the Expression Builder preview pane:
But if I then click OK, the labels disappear completely and nothing is rendered, while in the Expression Builder, everything still looks fine.
I'm trying to understand why it doesn't work as expected but have no clue what else to try or where to look.
Any suggestions?





