[QGIS-Developer] Bug in QgsPathResolver ?
David Marteau
dmarteau at 3liz.com
Tue Apr 23 14:52:30 PDT 2019
> Le 23 avr. 2019 à 23:35, Nyall Dawson <nyall.dawson at gmail.com> a écrit :
>
> On Fri, 19 Apr 2019 at 23:24, David Marteau <dmarteau at 3liz.com <mailto:dmarteau at 3liz.com>> wrote:
>>
>> Hi devs,
>>
>> I have a strange behavior with QgsPathResolver that prevent layer to be loaded if a QgsProject read config file from relative path:
>>
>> The problem has been reduced to the following behavior (pyQgis):
>>
>> ```
>> # Init a QgsPathResolver as with a relative path
>> pr = QgsPathResolver('./geography/data/france_parts.qgs')
>
> Isn't this an odd/dangerous/fragile situation to begin with? I'd be in
> favour of requiring QgsPathResolver to accept only absolute paths in
> the constructor.
Hi,
That would mean that only absolute may be passed to QgsProjet::read(), why not, it's a decision to make; I cannot
tell it there would be side effects or not.
but IMHO, in all case, I think we should have explicite error/warnings and not end with
meaningless path (see below) and ' unavailable layers found' errors which is confusing.
Regards
David,
>
> Nyall
>
>
>>
>> pr.readPath('./france_parts/france_parts.shp')
>> # Output -> '/geography/data/france_parts/france_parts.shp'
>> # Note the leading '/'
>> ```
>>
>> Worst:
>> ```
>> pr = QgsPathResolver('../geography/data/france_parts.qgs')
>>
>> pr.readPath('./france_parts/france_parts.shp')
>> # Output -> '/../geography/data/france_parts/france_parts.shp'
>> # which is a meaningless path
>> ```
>>
>> The side effect is that if you do:
>> ```
>> prj = QgsProject()
>> prj.read("./geography/data/france_parts.qgs")
>> ```
>> then you get the error:
>> ```
>>
>> Qgis OGR: Cannot open /geography/data/france_parts/france_parts.shp.()
>> Qgis : 1 unavailable layers found:
>> Qgis : * ./france_parts/france_parts.shp
>>
>> ```
>>
>> This is with Qgis 3.6.1
>>
>> Can anybody confirm that this behavior is a bug ? I will submit a PR if this is the case.
>> Thanks,
>>
>> Cheers
>> David
>>
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org <mailto:QGIS-Developer at lists.osgeo.org>
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190423/14f4059d/attachment.html>
More information about the QGIS-Developer
mailing list