Skip to content

test: managed fields excluded from projection are dropped on INSERT - #1688

Draft
larsPlessing wants to merge 1 commit into
mainfrom
worktree-repro-20583
Draft

test: managed fields excluded from projection are dropped on INSERT#1688
larsPlessing wants to merge 1 commit into
mainfrom
worktree-repro-20583

Conversation

@larsPlessing

Copy link
Copy Markdown
Contributor

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 generated INSERT and end up NULL in the database — instead of being filled by the default managed handler.

Root cause (per bisect): removal of resolveView() from SQLService.cqn2sql() in 2.9.0. In db-service/lib/cqn2sql.js, INSERT_entries() builds its column list from q.elements (the service-projection elements) and managed() 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 entity db.fooManaged : managed + restricted projection fooManagedRestricted { ID, value }.
  • sqlite/test/general/managed.test.js: a test that POSTs through the restricted projection, then reads the underlying db.fooManaged row.

Expected result

The new test fails on current HEAD (it documents the bug):

expected {
  ID: 99, createdAt: null, createdBy: null,
  modifiedAt: null, modifiedBy: null, value: 'test'
} to contain subset { ID: 99, createdBy: 'anonymous', value: 'test' }

Draft — reproduction only, not a fix.

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).
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