[QGIS-Developer] References to old datasources are left in project file when datasource is changed

Lauri Kajan lauri.kajan at gmail.com
Thu Jun 2 04:30:42 PDT 2022


Hi all,

I have noticed that references to old datasources are left in qgs xml
project file when datasource of layers are changed. Tested with LTR and
with the latest nightly.
This happens when there are relationships defined between layers.

When datasources are changed one value of the editwidget's options keeps
pointing to the old location. XPath for the element containing the
problematic datasource reference is:
/qgis/projectlayers/maplayer/fieldConfiguration/field/editWidget[@type='RelationReference']/config/Option[@type='Map']/Option[@name='ReferencedLayerDataSource']/@value

What is the meaning of this ReferencedLayerDataSource? Does it do anything?

Problem raised when I changed datasources of layers from development
database to point to test database. When committing the changes to our repo
I noticed that the project still had references to the development database.

For test/demo purposes I now have two geopackages test.gpkg and prod.gpkg
which both contain layers 'parent' and 'child'.
In the QGIS project there is a relationship defined between these
"parent[fid] <-> child[parent_fid]".

If the project is first built to read parent and child layers from the
test.gpkg and then datasources of these layers are changed to prod.gpkg
using the "Change Data Source ..." tool from the context menu of the layers
then this problematic element in qgs project file is still:
<Option name="ReferencedLayerDataSource" type="QString"
value="C:/Users/lauri/projektit/tmp/qgis-relation-test/test.gpkg|layername=parent"></Option>
This should point to the prod.gpkg. The datasource of the parent MapLayer
is right "<datasource>./prod.gpkg|layername=parent</datasource>"

Another thing I noticed is that the value is an absolute path of the
datasource even when QGIS should use relative paths.


Does QGIS use this ReferencedLayerDataSource for anything? Why is the
datasource even duplicated here?
Should I create an issue for this? If yes should this
ReferencedLayerDataSource Option just be removed or fix the value to
relative and to match the datasource of the actual layer.


Thanks,

Lauri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220602/b0b102ab/attachment.htm>


More information about the QGIS-Developer mailing list