Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Value relation widget settings lost on import of layer definition file #30115
Describe the bug
On adding a group of layers, using in a layer definition file, within which the use of value relations is defined for the attribute form, the value relation settings are not preserved correctly. This applies specifically where the value relation in one layer references the data in a second layer (or table).
The issue seems to be that the layers are identified with new names once imported, but the old names are not changed in the value relation.
How to Reproduce
Define two simple layers (with or without geometry). Define that the attribute form from one uses a value relation widget to access potential values from the other. Group these two layers. Test it works (save project to reference later). Save (export) the group as a layer definition file. In a new project add the layer definition file.
Check that the the value relation no longer works (the widget in the second layer will have lost the reference to the first layer).
Additional troubleshooting info below.
QGIS and OS versions
QGIS code revision
On inspection, the QGIS layer definition file has references given to the layers.
The widget references this:
On importing the layer definition file the main reference changes:
But the text defining the widget remains unchanged.
I'm very deeply out of my depth in looking at the code, but I've made an attempt to understand this fix. Wouldn't it be better if a way could be found to refer back to the imported qlr file? Forgive my clumsy use of language/terms but there's an established link between the old layer name (id?) and the layer referred to in the value relation. Is it possible to search the qlr file for this link? If nothing else, this qlr file defines the human-friendly name that the layer is given in the layers panel. Sorry - please feel free to tell me I'm being ignorant if this is silly... I'm just reflecting on how I think the error is arising and that the data exists that links one to the other - so that a search shouldn't be required (and might introduce other issues where layers are loaded more than once in a project).
@RW-gis long story short: when you saved the QLR you only saved the layer ID of the related layer.
After the patch, we now save the related layer name along the ID, so that when the QLR is imported we can first search for a related layer with the same ID (this was already working) but (this is new) if there is no match we can use the layer name to try to find another match, of course this is not perfect because we might have more than one layer with the same name (bad practice but it's allowed), in that case we pick up the first match and hope for the best, it will probably work in 99.9% of the cases.
I think I understand. However can you confirm that you noticed that I was referring to a situation where the referenced layer was also being loaded up by the same qlr (because it loads both the referencing layer and the referenced layer in one single qlr). I can see that there would naturally be an issue of needing to search for the referenced layer if this is loaded separately (and your solution is clearly a solid/valuable one in that case), but that wasn't the case in the situation I raise. My qlr contains all the information needed to ensure the link to the correct referenced layer. (But, again, acknowledging my ignorance...)
Yes - so for clarity (summary of the technicalities I spotted) - the qlr file initially records an ID for the referenced layer, and uses that in defining the workings of the value relation widget used in editing the second layer. On import QGIS gives all the layers new IDs (visible in the QGIS project file) - but it fails to copy this change to the widget definition (it can be seen in the file that these keep the old ID).