Repository navigation
fix: populate CREATEDBY from session user instead of CURRENT_USER() - #375
Conversation
Add `getUser()` to `AbstractChangeTrackingTrigger` which reads the `user_id` session variable (set by the CAP runtime) and falls back to `CURRENT_USER()`. The H2 codegen now passes `createdBy` as a bind parameter for every changelog INSERT instead of embedding `CURRENT_USER()` directly in the SQL, so the recorded user reflects the authenticated application user rather than the DB connection user.
SummaryThe following content is AI-generated and provides a summary of the pull request: Fix changelog CREATEDBY to use CAP session userBug Fix🐛 Updated H2 change-tracking trigger generation so changelog entries store the authenticated CAP application user in Changes
PR Bot InformationVersion:
|
with that we can use the session variable already set by default by the cap java runtime.
this is actually not needed here.
|
@Schmarvinius @swaldmann tests for HANA fail with timeout. I am pretty sure that this is not caused by my change as this is Java only and should not influence any of the generation for HANA. |
9426554
…DS 9 stack npm i <tgz> in the "Install branch" step re-resolves deps inside perf-bookshop, picking up @cap-js/sqlite@3.x which requires @sap/cds@^10, conflicting with the CDS 9 matrix. Adding an overrides entry forces npm to use ^2 during that install.
…inning CDS 9 stack" This reverts commit e7fbb40.
This reverts commit 9426554.
agoerler
left a comment
There was a problem hiding this comment.
If this trigger runs in the same transaction as the tx that does the changes on H2 the session context variables @applicationuser and @now (the logical transaction timestamp) should always be set. Therefore we should be able just to use @applicationuser and @now in the SQL.
Moreover, we can't use CURRENT_TIMESTAMP() as this determines the timestamp on the DB but we need the logical transaction timestamp. Also we can't use CURRENT_USER() as this would be the user we use to connect to H2. But we need the application user instead.
Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
a462ac0
…rors After `String locale` and `String createdBy` were removed from the fire() method template, two generated-code bugs remained: 1. `_wrapInTryCatch` emitted `stmt.setString(N, locale)` for localized association columns (whose `labelRes.bindings` contains `'locale'`), causing `cannot find symbol: variable locale` at Java compile time. Fix: resolve the `'locale'` binding to `getLocale(conn)` inline. 2. The composition parent INSERT VALUES still used `CURRENT_TIMESTAMP(), ?` for CREATEDAT/CREATEDBY while `'createdBy'` had been dropped from allBindings, causing a PreparedStatement parameter count mismatch. Fix: use `@now, @applicationuser` session variable literals for the composition parent case too, consistent with the non-parent case.
the requested changes were applied
|
@stefanrudi @Schmarvinius I had to make some changes after last proposed changes from @agoerler - can you please re-approve this PR? |
Summary
getUser()toAbstractChangeTrackingTriggerwhich reads theuser_idsession variable set by the CAP runtime, falling back toCURRENT_USER()when it is absentCURRENT_USER()SQL function in every changelogINSERTwith a bind parameter?, bound to thecreatedByvariable resolved at trigger runtimeCREATEDBYvalue reflects the authenticated application user rather than the DB connection userTest plan
CREATEDBYCURRENT_USER()whenuser_idsession variable is not set