New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value relation widget settings lost on import of layer definition file #30115
Comments
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...) |
Hmm no, in fact I didn't notice it, so your case is a bit different. I verified that the ID actually changes (something is appended to the original id). I'l check if there is a reason for that change. |
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). |
I'm fixing the issue for QLR, if the same issue exists in embedded project please open a new ticket and attach a sample project. |
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
Windows 10
QGIS version
3.4.7-Madeira
QGIS code revision
5c56989
Compiled against Qt
5.11.2
Running against Qt
5.11.2
Compiled against GDAL/OGR
2.4.1
Running against GDAL/OGR
2.4.1
Compiled against GEOS
3.7.0-CAPI-1.11.0
Running against GEOS
3.7.2-CAPI-1.11.0 b55d2125
PostgreSQL Client Version
9.2.4
SpatiaLite Version
4.3.0
QWT Version
6.1.3
QScintilla2 Version
2.10.8
Compiled against PROJ
520
Running against PROJ
5.2.0
Additional context
On inspection, the QGIS layer definition file has references given to the layers.
<layer-tree-layer source=....... ......name="valid_things" id="valid_things20180122163558679">
The widget references this:
On importing the layer definition file the main reference changes:
<layer-tree-layer... ...id="valid_things201906061506574996932" ...>
But the text defining the widget remains unchanged.
The text was updated successfully, but these errors were encountered: