test: managed fields excluded from projection are dropped on INSERT - #1688
Draft
larsPlessing wants to merge 1 commit into
Draft
test: managed fields excluded from projection are dropped on INSERT#1688larsPlessing wants to merge 1 commit into
larsPlessing wants to merge 1 commit into
Conversation
Reproduces cap/issues#20583: since @cap-js/db-service@2.9.0, managed audit
fields (createdBy/createdAt/modifiedBy/modifiedAt) that are not exposed in a
service projection are silently dropped from the generated INSERT and end up
NULL in the database, instead of being filled by the default managed handler.
Adds a base entity db.fooManaged and a restricted projection
fooManagedRestricted { ID, value } to the sqlite general model, plus a failing
test that POSTs through the projection and reads the underlying DB row.
This test is expected to FAIL on current HEAD (it documents the bug).
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.
Repro (failing test) for cds-dbs#1576
Since
@cap-js/db-service@2.9.0, managed audit fields (createdBy/createdAt/modifiedBy/modifiedAt) that are not exposed in a service projection are silently dropped from the generatedINSERTand end upNULLin the database — instead of being filled by the default managed handler.Root cause (per bisect): removal of
resolveView()fromSQLService.cqn2sql()in 2.9.0. Indb-service/lib/cqn2sql.js,INSERT_entries()builds its column list fromq.elements(the service-projection elements) andmanaged()walks that same map, so any managed field the projection omits is invisible to both and never injected.What this PR adds
sqlite/test/general/model.cds: base entitydb.fooManaged : managed+ restricted projectionfooManagedRestricted { ID, value }.sqlite/test/general/managed.test.js: a test that POSTs through the restricted projection, then reads the underlyingdb.fooManagedrow.Expected result
The new test fails on current HEAD (it documents the bug):
Draft — reproduction only, not a fix.