Skip to content

Commit

Permalink
Correctly handle null value coded values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 30, 2021
1 parent 4d24b6e commit 65ec930
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1390,7 +1390,10 @@ void QgsOgrProvider::loadFields()
while ( codedValue && codedValue->pszCode )
{
const QString code( codedValue->pszCode );
const QString value( codedValue->pszValue );
// if pszValue is null then it indicates we are working with a set of acceptable values which aren't
// coded. In this case we copy the code as the value so that QGIS exposes the domain as a choice of
// the valid code values.
const QString value( codedValue->pszValue ? codedValue->pszValue : codedValue->pszCode );

QVariantMap config;
config[ value ] = code;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_ogr.py
Expand Up @@ -1275,7 +1275,7 @@ def testFieldDomains(self):
enum_field = fields[fields.lookupField('with_enum_domain')]
enum_setup = enum_field.editorWidgetSetup()
self.assertEqual(enum_setup.type(), 'ValueMap')
self.assertTrue(enum_setup.config()['map'], [{'one': '1'}, {'': '2'}])
self.assertTrue(enum_setup.config()['map'], [{'one': '1'}, {'2': '2'}])


if __name__ == '__main__':
Expand Down

0 comments on commit 65ec930

Please sign in to comment.