Re: [QGIS-Developer] Bug in QgsPathResolver ?

2019-04-23 Thread David Marteau


> Le 23 avr. 2019 à 23:35, Nyall Dawson  a écrit :
> 
> On Fri, 19 Apr 2019 at 23:24, David Marteau  > 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@lists.osgeo.org 
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
>> 
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
>> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Bug in QgsPathResolver ?

2019-04-23 Thread Nyall Dawson
On Fri, 19 Apr 2019 at 23:24, David Marteau  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.

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@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer