diff --git a/src/Field.php b/src/Field.php index 3bebbe4cfa..e3f938eebf 100644 --- a/src/Field.php +++ b/src/Field.php @@ -164,7 +164,7 @@ public function __construct() $value = $persistence->typecastLoadField($this, $value); if ($value === null) { - if ($this->required/* known bug, see https://github.com/atk4/data/issues/575, fix in https://github.com/atk4/data/issues/576 || $this->mandatory*/) { + if ($this->required || $this->mandatory) { throw new Exception('Must not be null'); } diff --git a/src/Persistence.php b/src/Persistence.php index a25fe6751b..81cff1a3d0 100644 --- a/src/Persistence.php +++ b/src/Persistence.php @@ -179,14 +179,7 @@ public function typecastSaveRow(Model $model, array $row): array $field = $model->getField($fieldName); - $value = $this->typecastSaveField($field, $value); - - // check null values for mandatory fields - if ($value === null && $field->mandatory) { - throw new ValidationException([$field->short_name => 'Mandatory field value cannot be null'], $field->getOwner()); - } - - $result[$field->getPersistenceName()] = $value; + $result[$field->getPersistenceName()] = $this->typecastSaveField($field, $value); } return $result; diff --git a/tests/FieldTest.php b/tests/FieldTest.php index a81f4e28aa..e6f553741b 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -65,11 +65,8 @@ public function testMandatory1(): void $m->set('foo', 'abc'); $m->set('foo', ''); - /* known bug, see https://github.com/atk4/data/issues/575, fix in https://github.com/atk4/data/issues/576 - $this->expectException(ValidationException::class);*/ + $this->expectException(ValidationException::class); $m->set('foo', null); - - $this->assertTrue(true); // no exceptions } public function testRequired1(): void diff --git a/tests/Util/DeepCopyTest.php b/tests/Util/DeepCopyTest.php index 71babd6a63..719296adc5 100644 --- a/tests/Util/DeepCopyTest.php +++ b/tests/Util/DeepCopyTest.php @@ -332,7 +332,6 @@ public function testDeepError(): void $dc = new DeepCopy(); $this->expectException(DeepCopyException::class); - try { $invoice = $dc ->from($quote) @@ -340,8 +339,8 @@ public function testDeepError(): void ->to($invoice) ->with(['Lines']) ->copy(); - } catch (\Atk4\Data\Util\DeepCopyException $e) { - $this->assertSame('Mandatory field value cannot be null', $e->getPrevious()->getMessage()); + } catch (DeepCopyException $e) { + $this->assertSame('Must not be null', $e->getPrevious()->getMessage()); throw $e; }