Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 0f49cb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsrelation.cpp
Expand Up @@ -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 ) );
}

Expand Down
15 changes: 15 additions & 0 deletions tests/src/python/test_qgsrelation.py
Expand Up @@ -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()

Expand Down

0 comments on commit 0f49cb9

Please sign in to comment.