Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a proper QgsProviderConnectionException from python table() #39152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()