Bug report #21150

Delimitedtext layer saves absolute path when project in relative path mode

Added by Adam Liddell about 5 years ago. Updated about 5 years ago.

Status:Closed
Priority:High
Assignee:Alessandro Pasotti
Category:Project Loading/Saving
Affected QGIS version:3.4.4 Regression?:Yes
Operating System:Windows 7 Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:28968

Description

When saving a project with 'Save paths' set to 'relative', the paths for any delimited text layers are saved as absolute 'file:///...' paths in the project file.

Steps to reproduce:
- Create new project and set 'Save paths' to 'relative'
- Add a delimited text layer, such as a CSV file
- Save the project
- Inspect the produced XML file, the 'layer-tree-layer' node will have an absolute path in the 'source' attribute
- Any vector layers etc will have correct relative paths, as expected

Expected behaviour:
When in relative paths mode, the delimited text layer should save its source as a relative path

This breaks being able to produce shareable projects.
Manually rewriting the paths to be relative (e.g. file://../data/file.csv) still works when reloading the project, but on the next save they will be overwritten with absolute paths again.

Associated revisions

Revision 22c22e8e
Added by Alessandro Pasotti about 5 years ago

Strip file:// from local files path before resolving

Fixes #21150 - Delimitedtext layer saves absolute path
when project in relative path mode

History

#1 Updated by Giovanni Manghi about 5 years ago

  • Regression? changed from No to Yes
  • Category changed from Data Provider/Delimited Text to Project Loading/Saving
  • Priority changed from Normal to High

confirmed and if I'm not wrong this is a regression.

#2 Updated by Alessandro Pasotti about 5 years ago

  • Assignee set to Alessandro Pasotti

#3 Updated by Alessandro Pasotti about 5 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

#4 Updated by Adam Liddell about 5 years ago

  • Status changed from Closed to Reopened

I've tested on 3.6.0, which contains the above patch, and the issue is still present when following the original steps to reproduce.

#5 Updated by Alessandro Pasotti about 5 years ago

  • Status changed from Reopened to Feedback

I cannot reproduce the bug, I explain it better:

What you originally filed was a bug because the csv path was not set as relative in the tag named "datasource" that is the real path of the data source, and that bug is now fixed: I cannot reproduce it after the patch and it is proteced by a test case which is not failing.

Btw, there is another place where the path is stored and you correctly mentioned it as 'layer-tree-layer', that value is never used inside QGIS (I honestly dont' know what is its purpose).

Did you really try to move the project in another folder (with its relative data) and reproduce the issue or did you just check for 'layer-tree-layer' 'source' value?

I'm pretty sure that the behavior that you described in the ticket is now fixed, it is not fixed the 'layer-tree-layer' 'source' path because it did not produce any effect.

Can you please confirm?

#6 Updated by Adam Liddell about 5 years ago

Yes, the absolute path is only appearing in the layer-tree-layer source value now. I wasn't aware that the field was not used within QGIS, hence the reopening when I noticed it was still there.
If it indeed has no effect, I agree this can close again; although it seems unusual that only the CSV nodes get an absolute path in that attribute whereas vector layers do not.

#7 Updated by Alessandro Pasotti about 5 years ago

In any event I'm going to fix 'layer-tree-layer' + 'source' too, to avoid any confusion.

The reason why it only affected CSV (well, more precisely, the reason why does not affect shapefiles) is that the CSV uri is internally stored like this:

'file:///home/Maps/test_set/DHH_facilities.csv?type=csv&detectTypes=yes&xField=Longitude&yField=Latitude&crs=EPSG:4326&spatialIndex=no&subsetIndex=no&watchFile=no'

while shapefile is stored like this:

'file:///home/Maps/test_set/DHH_facilities.shp'

the extra URL-like stuff was making the check for file existence to fail.

#8 Updated by Adam Liddell about 5 years ago

Ok, that makes sense, thank you

#9 Updated by Alessandro Pasotti about 5 years ago

  • Status changed from Feedback to In Progress

PR, fixes 'layer-tree-layer' + 'source' too: https://github.com/qgis/QGIS/pull/9273

#10 Updated by Alessandro Pasotti about 5 years ago

  • Resolution set to fixed/implemented
  • Status changed from In Progress to Closed
  • Pull Request or Patch supplied changed from No to Yes

Also available in: Atom PDF