Skip to content
Permalink
Browse files

Don't crash when a relation is created where the field names defined …

…in the relation differ in case from the layer's field names
  • Loading branch information
nyalldawson committed Feb 12, 2021
1 parent 2e81dbc commit 0f49cb909732882e4c0b3ba26a6987fff95e29ea
Showing with 16 additions and 1 deletion.
  1. +1 −1 src/core/qgsrelation.cpp
  2. +15 −0 tests/src/python/test_qgsrelation.py
@@ -233,7 +233,7 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes

for ( const FieldPair &pair : qgis::as_const( d->mFieldPairs ) )
{
int referencingIdx = referencingLayer()->fields().indexFromName( pair.referencingField() );
int referencingIdx = referencingLayer()->fields().lookupField( pair.referencingField() );
conditions << QgsExpression::createFieldEqualityExpression( pair.referencedField(), attributes.at( referencingIdx ) );
}

@@ -147,6 +147,21 @@ def test_getReferencedFeature(self):
assert f.isValid()
assert f[0] == 'foo'

# try mixing up the field pair field name cases -- we should be tolerant to this
rel2 = QgsRelation()
rel2.setId('rel1')
rel2.setName('Relation Number One')
rel2.setReferencingLayer(self.referencingLayer.id())
rel2.setReferencedLayer(self.referencedLayer.id())
rel2.addFieldPair('ForeignKey', 'Y')

feat = next(self.referencingLayer.getFeatures())

f = rel2.getReferencedFeature(feat)

assert f.isValid()
assert f[0] == 'foo'

def test_fieldPairs(self):
rel = QgsRelation()

0 comments on commit 0f49cb9

Please sign in to comment.