Skip to content

Commit

Permalink
Merge pull request #30265 from troopa81/source_missing_keyColumn
Browse files Browse the repository at this point in the history
Update datasource when using postgres provider so we have the key column in it
  • Loading branch information
elpaso committed Jun 27, 2019
2 parents 7761f5f + 9c90fdf commit f1bd39d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1636,6 +1636,9 @@ bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProv

if ( mProviderKey == QLatin1String( "postgres" ) )
{
// update datasource from data provider computed one
mDataSource = mDataProvider->dataSourceUri( false );

QgsDebugMsgLevel( QStringLiteral( "Beautifying layer name %1" ).arg( name() ), 3 );

// adjust the display name for postgres layers
Expand Down
8 changes: 8 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -1101,6 +1101,14 @@ def testReadExtentOnTable(self):

self.assertEqual(vl2.extent(), originalExtent)

def testDeterminePkey(self):
"""Test primary key auto-determination"""

vl = QgsVectorLayer(self.dbconn + ' sslmode=disable srid=4326 type=POLYGON table="qgis_test"."authors" sql=', 'test', 'postgres')
self.assertTrue(vl.isValid())
self.assertTrue(vl.dataProvider().hasMetadata())
self.assertTrue("key='pk'" in vl.source())

def testCheckPkUnicityOnView(self):
# vector layer based on view

Expand Down

0 comments on commit f1bd39d

Please sign in to comment.