Skip to content

Commit

Permalink
Return a proper QgsProviderConnectionException from python table()
Browse files Browse the repository at this point in the history
Fixes #39151
  • Loading branch information
elpaso authored and nyalldawson committed Oct 3, 2020
1 parent 096aa95 commit b0189b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsabstractdatabaseproviderconnection.h
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions tests/src/python/test_qgsproviderconnection_postgres.py
Expand Up @@ -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.