Skip to content
Permalink
Browse files

Return a proper QgsProviderConnectionException from python table()

Fixes #39151
  • Loading branch information
elpaso authored and nyalldawson committed Oct 3, 2020
1 parent 096aa95 commit b0189b41494927509e98dacbb06d99a57435e34b
@@ -487,7 +487,7 @@ Raises a QgsProviderConnectionException if any errors are encountered.
%End


virtual QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const;
virtual QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const throw( QgsProviderConnectionException );
%Docstring
Returns information on a ``table`` in the given ``schema``.
Raises a QgsProviderConnectionException if any errors are encountered or if the table does not exist.
@@ -526,7 +526,7 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv
* \note Not available in Python bindings
* \since QGIS 3.12
*/
virtual QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const;
virtual QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const SIP_THROW( QgsProviderConnectionException );

/**
* Returns information on the tables in the given schema.
@@ -354,6 +354,14 @@ def test_fields_no_pk(self):
'out_db',
'spatial_index'}))

def test_exceptions(self):
"""Test that exception are converted to Python QgsProviderConnectionException"""

md = QgsProviderRegistry.instance().providerMetadata('postgres')
conn = md.createConnection(self.uri, {})
with self.assertRaises(QgsProviderConnectionException):
conn.table('my_not_existent_schema', 'my_not_existent_table')


if __name__ == '__main__':
unittest.main()

0 comments on commit b0189b4

Please sign in to comment.
You can’t perform that action at this time.