From 450849a26fe579d7225f74800ea70ae294d305ef Mon Sep 17 00:00:00 2001 From: soyuka Date: Fri, 12 Jun 2026 15:19:30 +0200 Subject: [PATCH] test(mongodb): failing repro for ODM nullable field unset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ODM's Field nullable flag controls whether a null value is persisted as an explicit null key or the key is omitted from the document — it does not mean the field rejects null. DoctrineExtractor::getType() feeds ClassMetadata::isNullable() into the TypeInfo Type nullable flag, so a plain #[Field(type:'string')] (default nullable=false) yields a non-nullable Type and PATCH {"field": null} fails with a type error. This is the failing repro the maintainer requested before deciding on the fix direction. No production code is changed; the fix is pending a design decision. Refs #3746 --- .../Tests/PropertyInfo/DoctrineExtractorTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php index da527ba5751..2ec24a6ac79 100644 --- a/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -271,6 +271,21 @@ public static function typesProvider(): iterable yield ['notMapped', null]; } + /** + * In ODM, a Field's `nullable` flag does not mean "may hold null" — it controls whether a null + * value is persisted as an explicit null key or the key is omitted from the document. Every ODM + * field can therefore receive null, so the extracted TypeInfo Type must permit null even when the + * mapping uses the default `nullable=false`. Otherwise PATCH {"field": null} is rejected with + * "The type of the ... attribute must be ..., NULL given." (issue #3746). + */ + public function testExtractScalarFieldPermitsNull(): void + { + $type = $this->createExtractor()->getType(DoctrineDummy::class, 'string'); + + $this->assertNotNull($type); + $this->assertTrue($type->isNullable(), 'ODM scalar fields are always nullable; the extracted type must permit null.'); + } + public function testGetPropertiesCatchException(): void { $this->assertNull($this->createExtractor()->getProperties('Not\Exist'));