Skip to content

fix: Properly relink csn clone - #207

Merged
daogrady merged 10 commits into
mainfrom
fix/linked-csn-prototype-after-clone
Nov 4, 2026
Merged

daogrady merged 10 commits into
mainfrom
fix/linked-csn-prototype-after-clone

Conversation

@daogrady

@daogrady daogrady commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #204

In the latest version, we introduced a call to cds.clone as very first step, to make sure we do not modify the passed-in CSN by reference.
As cds.clone uses structuredClone under the hood, it destroys the prototype chain of the clone, which causes problems downstream when a LinkedCSN is being passed in.
We can remedy this by linking the CSN again after the clone, if the user passed in a LinkedCSN.

Reproduction can be found in cap/sherlock/issues/903
(confirmed the fix addresses the problem)

Don't merge yet. We will discuss fixing this problem directly within cds.clone, instead of patching around it on the call site.

Discussed: call site is reponsible for restoring linked properties.

@daogrady daogrady changed the title Properly relink csn clone fix: Properly relink csn clone Oct 15, 2026
@daogrady
daogrady marked this pull request as ready for review October 15, 2026 11:13
@daogrady
daogrady requested a review from tim-sh October 15, 2026 11:13
tim-sh
tim-sh previously approved these changes Oct 30, 2026

@tim-sh tim-sh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one Q…

Comment thread test/lib/compile/openapi.test.js Resolved
daogrady and others added 2 commits November 2, 2026 07:30
The previous test called toOpenApi() with a linked model and asserted
it returned a result, but this passed even on the unfixed code (compiler
v6 doesn't throw on unlinked CSN — only v7+ does).

Replace with a spy on cds.compile.to.edm that captures the prototype of
the CSN it receives. With the fix the cloned CSN is re-linked before EDM
compilation (LinkedCSN); without it a plain Object enters EDM, which
breaks cds-compiler v7+ on draft entity projections.

Also move @odata.draft.enabled onto the base entity (the actual scenario
from the bug report) rather than on the service.
@daogrady
daogrady requested a review from tim-sh November 2, 2026 07:11
@daogrady
daogrady merged commit 11bfe0f into main Nov 4, 2026
9 checks passed
@daogrady
daogrady deleted the fix/linked-csn-prototype-after-clone branch November 4, 2026 15:32
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.

[BUG] <recompile>.csn:6708: Error: Element “IsActiveEntity” does not result from the query

2 participants