Skip to content

Commit

Permalink
Test for PG query layer duplicated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed May 29, 2020
1 parent c8eee70 commit 04f7a8f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -2387,6 +2387,19 @@ def testAddFeature(self):
self.assertFalse(l.dataProvider().addFeatures([f1, f2]),
'Provider reported no AddFeatures capability, but returned true to addFeatures')

def testDuplicatedFieldNamesInQueryLayers(self):
"""Test regresssion GH #36205"""

vl = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'__rid__\' table="(SELECT row_number() OVER () AS __rid__, * FROM (SELECT * from qgis_test.some_poly_data a, qgis_test.some_poly_data b where ST_Intersects(a.geom,b.geom)) as foo)" sql=', 'test_36205', 'postgres')
self.assertTrue(vl.isValid())
self.assertEqual(vl.featureCount(), 3)

# This fails because the "geom" field and "pk" fields are ambiguous
# There is no easy fix: all duplicated fields should be explicitly aliased
# and the query internally rewritten
#feature = next(vl.getFeatures())
#self.assertTrue(vl.isValid())


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

0 comments on commit 04f7a8f

Please sign in to comment.