Skip to content
Permalink
Browse files
Revert "Fix constraint check when AllowMulti"
This reverts commit 355e3fb.
  • Loading branch information
elpaso authored and m-kuhn committed Dec 27, 2021
1 parent 7418f76 commit fb0d46662b051a9eeb2ca800af215456fbc614a7
Showing with 8 additions and 28 deletions.
  1. +2 −13 src/core/qgsvectorlayerutils.cpp
  2. +6 −15 tests/src/python/test_qgsvectorlayerutils.py
@@ -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;
@@ -32,7 +32,6 @@
QgsWkbTypes,
QgsCoordinateReferenceSystem,
QgsVectorLayerJoinInfo,
QgsEditorWidgetSetup,
NULL
)
from qgis.testing import start_app, unittest
@@ -258,7 +257,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)
@@ -267,6 +266,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)
@@ -278,6 +278,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)

@@ -291,6 +292,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,
@@ -308,6 +310,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,
@@ -342,19 +345,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 """

0 comments on commit fb0d466

Please sign in to comment.