Skip to content

test(mongodb): failing repro for ODM nullable field unset#8298

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/odm-nullable-unset-field-3746-test
Open

test(mongodb): failing repro for ODM nullable field unset#8298
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/odm-nullable-unset-field-3746-test

Conversation

@soyuka

@soyuka soyuka commented Jun 12, 2026

Copy link
Copy Markdown
Member

Context

Failing-repro PR requested by @soyuka in the design discussion for #3746.

In Doctrine MongoDB ODM, a #[Field]'s nullable flag does not mean "the field may hold null". It controls whether a PHP null is persisted as an explicit null key or the key is omitted from the document (nullable=false, the default = omit). Every ODM field can therefore receive null.

src/Doctrine/Odm/PropertyInfo/DoctrineExtractor::getType() feeds ClassMetadata::isNullable() into the TypeInfo Type nullable flag, so a plain #[Field(type: 'string')] yields a non-nullable Type. As a result PATCH {"field": null} is rejected with The type of the "field" attribute must be "string", "NULL" given. instead of unsetting the field.

Scope

Per the maintainer's note ("I dont care much about property info only type info path"), this targets the TypeInfo getType() path only. The legacy getTypes() property-info path is untouched.

This PR

A single failing test (testExtractScalarFieldPermitsNull) asserting the expected-correct behavior — an ODM scalar field's extracted type permits null. It fails on current 4.3 HEAD, demonstrating the bug.

No production code is changed. The fix direction is pending a maintainer decision between the three options posted in the validation thread (always-nullable for ODM scalars / defer to PHP property type / drop the flag).

Refs #3746

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 api-platform#3746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant