Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "Fix constraint check when AllowMulti"
This reverts commit 355e3fb.
  • Loading branch information
elpaso authored and github-actions[bot] committed Dec 11, 2021
1 parent f7d48d8 commit 2e91a3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
15 changes: 2 additions & 13 deletions src/core/vector/qgsvectorlayerutils.cpp
Expand Up @@ -431,20 +431,9 @@ bool QgsVectorLayerUtils::validateAttribute( const QgsVectorLayer *layer, const

if ( !exempt )
{
valid = valid && !value.isNull();

const bool allowMulti { field.editorWidgetSetup().config().value( QStringLiteral( "AllowMulti" ), false ).toBool() };
bool multiViolated { false };
if ( allowMulti )
{
multiViolated = value == QStringLiteral( "{}" );
valid = valid && ( !value.isNull() && ! multiViolated );
}
else
{
valid = valid && !value.isNull();
}

if ( value.isNull() || multiViolated )
if ( value.isNull() )
{
errors << QObject::tr( "value is NULL" );
notNullConstraintViolated = true;
Expand Down
21 changes: 6 additions & 15 deletions tests/src/python/test_qgsvectorlayerutils.py
Expand Up @@ -32,7 +32,6 @@
QgsWkbTypes,
QgsCoordinateReferenceSystem,
QgsVectorLayerJoinInfo,
QgsEditorWidgetSetup,
NULL
)
from qgis.testing import start_app, unittest
Expand Down Expand Up @@ -267,7 +266,7 @@ def test_validate_attribute(self):
# field expression check
layer.setConstraintExpression(1, 'fldint>5')

f = QgsFeature(layer.fields(), 2)
f = QgsFeature(2)
f.setAttributes(["test123", 6])
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertTrue(res)
Expand All @@ -276,6 +275,7 @@ def test_validate_attribute(self):
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertFalse(res)
self.assertEqual(len(errors), 1)
print(errors)
# checking only for provider constraints
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1,
origin=QgsFieldConstraints.ConstraintOriginProvider)
Expand All @@ -287,6 +287,7 @@ def test_validate_attribute(self):
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertFalse(res)
self.assertEqual(len(errors), 1)
print(errors)

layer.setConstraintExpression(1, None)

Expand All @@ -300,6 +301,7 @@ def test_validate_attribute(self):
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertFalse(res)
self.assertEqual(len(errors), 1)
print(errors)

# checking only for provider constraints
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1,
Expand All @@ -317,6 +319,7 @@ def test_validate_attribute(self):
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertFalse(res)
self.assertEqual(len(errors), 1)
print(errors)

# checking only for provider constraints
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1,
Expand Down Expand Up @@ -351,19 +354,7 @@ def test_validate_attribute(self):
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 1)
self.assertFalse(res)
self.assertEqual(len(errors), 2)

# Test AllowMulti with no selected values, see GH #46366
setup = QgsEditorWidgetSetup('ValueRelation', {'AllowMulti': True})
layer.setEditorWidgetSetup(0, setup)
layer.setFieldConstraint(0, QgsFieldConstraints.ConstraintNotNull)
f.setAttribute(0, QVariant())
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 0)
self.assertFalse(res)
f.setAttribute(0, '{}')
self.assertEqual(len(errors), 1)
res, errors = QgsVectorLayerUtils.validateAttribute(layer, f, 0)
self.assertFalse(res)
self.assertEqual(len(errors), 1)
print(errors)

def testCreateUniqueValue(self):
""" test creating a unique value """
Expand Down

0 comments on commit 2e91a3b

Please sign in to comment.