Skip to content

clarify @mandatory is not validated in deep updates - #2585

Open
mariayord wants to merge 4 commits into
mainfrom
mandatory-deep-update
Open

clarify @mandatory is not validated in deep updates#2585
mariayord wants to merge 4 commits into
mainfrom
mandatory-deep-update

Conversation

@mariayord

@mariayord mariayord commented May 20, 2026

Copy link
Copy Markdown
Contributor

Updated documentation regarding @mandatory annotation. There is no validation on @mandatory in deep updates usecase.

Removed section with @FieldControl, as it is mentioned already in Field Control below

Fixes: https://github.tools.sap/cap/cdsnode/issues/2637

@mariayord
mariayord requested a review from renejeglinsky as a code owner May 20, 2026 12:31
@mariayord
mariayord requested a review from agoerler May 20, 2026 12:32
@mariayord mariayord changed the title clarify @mandatory is not validated in deep updates, fix wrong info r… clarify @mandatory is not validated in deep updates May 20, 2026
@mariayord
mariayord requested a review from johannes-vogel May 20, 2026 12:36
Comment thread guides/services/constraints.md
Co-authored-by: René Jeglinsky <rene.jeglinsky@sap.com>
@renejeglinsky

Copy link
Copy Markdown
Contributor

@johannes-vogel @agoerler could you have a quick check here?

@renejeglinsky
renejeglinsky requested a review from danjoa as a code owner June 23, 2026 09:13
@rjayasinghe
rjayasinghe self-requested a review June 24, 2026 07:50
@renejeglinsky

Copy link
Copy Markdown
Contributor

@rjayasinghe Have you reviewed this PR?

@rjayasinghe

rjayasinghe commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The changes in this PR reflect the Node.js runtime — they do not hold for CAP Java.

The statement "@mandatory validation is not applied to nested data in deep update operations" is accurate for Node.js, but as written it reads as cross-runtime and is misleading for Java. Since these docs cover both runtimes, could we scope it per-runtime?

In CAP Java, @mandatory validation (MandatoryHandlerNotNullValidator) does recurse into nested data on deep updates, following the same cascade rules as persistence — i.e. into compositions by default (and any association carrying @cascade.update/@cascade.all). The only relaxation is partial-update semantics. Concretely, for a deep update:

Nested @mandatory field CAP Java behavior
omitted from the payload tolerated (partial-update semantics)
explicit null / "" in a composition rejected (VALUE_REQUIRED)
explicit null / "" in an association target tolerated

So for Java it's not "no validation on nested data" — it's "a missing mandatory value is not enforced on update, but an explicitly provided null inside a cascading composition still is."

This is backed by the unit tests in MandatoryHandlerTest (the composition-null case is asserted to fail; I've added coverage for the omitted-field case confirming it's tolerated).

Suggested framing: keep the current sentence under a Node.js tab, and for Java state that mandatory is validated in nested cascading targets, with only a missing value left unenforced (use not null if you also need presence enforced).

@mariayord

Copy link
Copy Markdown
Contributor Author

@rjayasinghe As I understand it, Java does not validate @mandatory, except for compositions where the value is explicitly set to null or ''.
@renejeglinsky In that case, I will document this as the Node.js behavior.
@rjayasinghe For Java, it's up to you whether you want to document this partially supported feature.

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.

3 participants