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

Fix PG trust metadata layer loading #38833

Merged
merged 2 commits into from
Sep 18, 2020
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
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c
}

QgsDataProvider::ProviderOptions options { context.transformContext() };
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
QgsDataProvider::ReadFlags flags;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @elpaso, if this line has to be updated, It has to be fixed in other files. Will you do it or do you want that I create a PR just for this ?

This line has been introduced with this PR #38464

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated code is totally equivalent, I just find redundant call the default ctor explicitly. It's more a style matter, nothing important.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rldhont np.

On another topic I did not check if the same quotedIdentifier / quotedValue mistake was done elsewhere with your original PR or any followup. Can you please check that it only affected PG?

if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
{
flags |= QgsDataProvider::FlagTrustDataSource;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3761,8 +3761,8 @@ bool QgsPostgresProvider::getGeometryDetails()
sql = QStringLiteral(
"SELECT t.typname FROM pg_type t inner join (SELECT pg_typeof(%1) typeof FROM %2.%3 LIMIT 1) g ON oid = g.typeof"
).arg( quotedIdentifier( geomCol ),
quotedValue( schemaName ),
quotedValue( tableName ) );
quotedIdentifier( schemaName ),
quotedIdentifier( tableName ) );
}
QgsDebugMsgLevel( QStringLiteral( "Getting the spatial column type: %1" ).arg( sql ), 2 );

Expand Down
39 changes: 38 additions & 1 deletion tests/src/python/test_provider_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
QgsProviderConnectionException,
)
from qgis.gui import QgsGui, QgsAttributeForm
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject, QByteArray
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject, QByteArray, QTemporaryDir
from qgis.PyQt.QtWidgets import QLabel
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument
Expand Down Expand Up @@ -2984,6 +2984,43 @@ def testUnrestrictedGeometryType(self):
self.assertTrue(lines.isValid())
self.assertTrue(polygons.isValid())

def testTrustFlag(self):
"""Test regression https://github.com/qgis/QGIS/issues/38809"""

vl = QgsVectorLayer(
self.dbconn +
' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."editData" (geom) sql=',
'testTrustFlag', 'postgres')

self.assertTrue(vl.isValid())

p = QgsProject.instance()
d = QTemporaryDir()
dir_path = d.path()

self.assertTrue(p.addMapLayers([vl]))
project_path = os.path.join(dir_path, 'testTrustFlag.qgs')
self.assertTrue(p.write(project_path))

del vl

p.clear()
self.assertTrue(p.read(project_path))
vl = p.mapLayersByName('testTrustFlag')[0]
self.assertTrue(vl.isValid())
self.assertFalse(p.trustLayerMetadata())

# Set the trust flag
p.setTrustLayerMetadata(True)
self.assertTrue(p.write(project_path))

# Re-read
p.clear()
self.assertTrue(p.read(project_path))
self.assertTrue(p.trustLayerMetadata())
vl = p.mapLayersByName('testTrustFlag')[0]
self.assertTrue(vl.isValid())


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