docs: document cds.drafts.enforceReadonly and the @readonly bypass hint - #2790
Open
rjayasinghe wants to merge 2 commits into
Open
docs: document cds.drafts.enforceReadonly and the @readonly bypass hint#2790rjayasinghe wants to merge 2 commits into
rjayasinghe wants to merge 2 commits into
Conversation
Explain that @readonly/@Core.Computed are enforced on drafts (during
DRAFT_NEW/DRAFT_PATCH) when cds.drafts.enforceReadonly is enabled, and
document the .hint("@readonly", false) statement hint to write such
fields from trusted custom code.
Closes cds-java/home#2828
Contributor
|
Hey @mofterdinger Could you provide your feedback for this PR? Thank you :) |
smahati
reviewed
Aug 20, 2026
|
|
||
| By default, `@readonly` and `@Core.Computed` fields are only enforced when a draft is activated, that means during the `CREATE` or `UPDATE` event on the active entity. Until then, such fields can still be changed on the draft, for example through an OData `PATCH` request. | ||
|
|
||
| To enforce these annotations on the draft already, during the `DRAFT_NEW` and `DRAFT_PATCH` events, set the [`cds.drafts.enforceReadonly`](./developing-applications/properties#cds-drafts-enforcereadonly) property (default `false`): |
Contributor
There was a problem hiding this comment.
Suggested change
| To enforce these annotations on the draft already, during the `DRAFT_NEW` and `DRAFT_PATCH` events, set the [`cds.drafts.enforceReadonly`](./developing-applications/properties#cds-drafts-enforcereadonly) property (default `false`): | |
| To enforce these annotations on the draft even before activation, during the `DRAFT_NEW` and `DRAFT_PATCH` events, set the [`cds.drafts.enforceReadonly`](./developing-applications/properties#cds-drafts-enforcereadonly) property (default `false`): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds prose documentation for the
cds.drafts.enforceReadonlyproperty injava/fiori-drafts.md(new Read-Only Fields in Drafts section):@readonly/@Core.Computedare enforced only at activation by default, and that settingcds.drafts.enforceReadonly: trueenforces them on the draft itself duringDRAFT_NEW/DRAFT_PATCH(so read-only fields can't be changed via ODataPATCHon the draft)..hint("@readonly", false)to intentionally write read-only / computed fields from trusted custom code (e.g. determinations), with a warning that managed (@cds.on.insert/@cds.on.update) and@Core.Immutablefields remain enforced regardless.Why
The property already appears in the generated properties table but had no prose explaining the custom-code implication or the bypass hint, which surfaced in a developer question.
Verification
npm run docs:buildpasses with no dead-link errors; the property cross-link anchor#cds-drafts-enforcereadonlymatches the generated id.ReadOnlyHandler).