[QGIS-Developer] createvectorTable error: Could not retrieve driver for connection

Richard Duivenvoorde rdmailings at duif.net
Fri Dec 2 05:03:36 PST 2022


Ok, I think I found the crux!

With your code QGIS 3.26 will CREATE a new geopackage... (if it is not there yet)
After which QGIS master is fine

BUT QGIS master apparently does NOT create a new geopackage with your code...
So IF there is an excisting test.gpkg, all is fine
IF there is not one, it depends on you QGIS version if it creates a fresh one or not?

Maybe some core dev can say something about this?

Regards,

Richard Duivenvoorde

On 12/2/22 13:53, Richard Duivenvoorde via QGIS-Developer wrote:
> Hi Raymond,
> 
> I've updated your test script a little:
> 
> gpkg_fn = '/tmp/test.gpkg'
> try:
>      print(QgsProviderRegistry.instance().providerList())
>      md = QgsProviderRegistry.instance().providerMetadata('ogr')
>      print(f'md = {md}')
>      conn = md.createConnection(gpkg_fn, {})
>      print(f'conn = {conn}')
>      fields = QgsFields()
>      fields.append(QgsField('key', QVariant.String))
>      fields.append(QgsField('value', QVariant.String))
>      conn.createVectorTable('', 'test', fields, QgsWkbTypes.NoGeometry, QgsCoordinateReferenceSystem(), True, {})
> except Exception as e:
>      print(f'ERROR: {e}')
> 
> As said: in my freshly compiled master, this fails to run with 'Could not retrieve driver for connection'
> It also fails on my 3.28.0 version I have in a Windows VM.
> 
> It DOES print the 'ogr' driver in the providerList() though.
> 
> Strange behaviour: after starting (the older compiled) Qgis 3.26 on the same Linux system (in 3.26 the script always seems to work...) QGIS master ALSO works!!!
> 
> So I thought it had something todo with loading different provider registries or so?
> Maybe master not having something but after starting 3.26 it was there?
> Or is it loading (different) gdal/ogr libs order?
> Did something change there?
> 
> Looking that the createConnection docs:
> https://qgis.org/pyqgis/master/core/QgsConnectionRegistry.html#qgis.core.QgsConnectionRegistry.createConnection
> I thought to see that your 'id' was only the filename, but adding ogr:// in front of it does not even work...
> So not sure if that createConnection doc is old, or if I'm looking in the wrong createConnection...
> 
> Anybody can
> 
> 
>>>
> On 12/2/22 12:30, Raymond Nijssen via QGIS-Developer wrote:
>> No one having a clue? Should I create an issue?
>>
>> Raymond
>>
>>
>> On 30-11-2022 18:08, Raymond Nijssen via QGIS-Developer wrote:
>>> Hi developers,
>>>
>>> Recently some users of my plugin started getting errors in the code that creates a .gpkg file with a table. I wrote a piece of test code:
>>>
>>> gpkg_fn = '/home/raymond/tmp/test.gpkg'
>>> md = QgsProviderRegistry.instance().providerMetadata('ogr')
>>> conn = md.createConnection(gpkg_fn, {})
>>> fields = QgsFields()
>>> fields.append(QgsField('key', QVariant.String))
>>> fields.append(QgsField('value', QVariant.String))
>>> conn.createVectorTable('', 'test', fields, QgsWkbTypes.NoGeometry, QgsCoordinateReferenceSystem(), True, {})
>>>
>>>
>>> That last line *sometimes* results in this error:
>>>
>>> _core.QgsProviderConnectionException: Could not retrieve driver for connection
>>>
>>>
>>>
>>> I cannot reproduce the error on my laptop (Linux), but Richard tried a few QGIS versions in both Windows and Linux and *sometimes* got the error and sometimes not. Even in the same application, the error disappeared after running another version of QGIS simultaneously... :/
>>>
>>> No clue if this error is GDAL or Qt or whatever related, pretty puzzling for me. Hope anyone can help!
>>>
>>> Kind regards,
>>> Raymond
>>> _______________________________________________
>>> QGIS-Developer mailing list
>>> QGIS-Developer at 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 at 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 at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the QGIS-Developer mailing list