Skip to content

fix: @changelog annotations on unmanaged associations#301

Open
stefanrudi wants to merge 8 commits intomainfrom
fix/unmanaged-assoc
Open

fix: @changelog annotations on unmanaged associations#301
stefanrudi wants to merge 8 commits intomainfrom
fix/unmanaged-assoc

Conversation

@stefanrudi
Copy link
Copy Markdown
Collaborator

  • Guard col.keys access to prevent crash for unmanaged associations
  • Fix SQLite trigger OF clause using wrong column name (assocName_fkField → fkField)
  • Fix SQLite buildAssocLookup WHERE using entity PK instead of FK field
  • Deduplicate OF clause columns in SQLite and HANA triggers
  • Add optimization to skip unnecessary subselect when @changelog path matches on-condition target key
  • Add test

@stefanrudi stefanrudi requested a review from a team as a code owner April 29, 2026 15:53
@hyperspace-insights
Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Fix: @changelog Annotations on Unmanaged Associations

Bug Fix

🐛 Resolves multiple issues with @changelog path annotations used on unmanaged associations, including build crashes, incorrect trigger SQL, and wrong lookup behavior.

Changes

  • lib/utils/change-tracking.js: Added a guard around col.keys access to prevent crashes when processing unmanaged associations. Refactored onMapping parsing to be shared between the lookup optimization check and the entry.on assignment. Added optimization to skip unnecessary subselect lookups when the @changelog path already references a target key available as a local foreign key field.

  • lib/sqlite/triggers.js: Fixed the OF clause in SQLite update triggers to use the correct column names for unmanaged associations (foreignKeyField instead of assocName_foreignKeyField). Added deduplication of OF clause columns using Set to prevent duplicate entries when a field is referenced by both a tracked element and an unmanaged association.

  • lib/sqlite/sql-expressions.js: Fixed buildAssocLookup to use the correct foreign key field reference in the WHERE clause for unmanaged associations (was incorrectly using the entity's primary key). Removed the now-unused entityKey parameter from buildAssocLookup and getLabelExpr.

  • lib/hana/triggers.js: Added deduplication of OF clause columns in HANA update triggers using Set, consistent with the SQLite fix.

  • tests/bookshop/db/incidents/schema.cds: Added @changelog annotation to the status4Nav unmanaged association field used for test coverage.

  • tests/integration/cds-features.test.js: Added an integration test verifying that changes on an unmanaged association element with a @changelog path annotation are correctly tracked and resolved with proper labels.

  • CHANGELOG.md / package.json: Bumped version to 2.0.0-beta.12 and documented all fixes and the new optimization.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.20.37

  • Event Trigger: pull_request.opened
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt
  • Correlation ID: b16d13b8-4681-4d4e-ac7f-d69fac4ee2d2
  • File Content Strategy: Full file content

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

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

The PR fixes several real bugs around unmanaged associations in change tracking (crash on col.keys, wrong column names in OF clauses, incorrect WHERE clause in buildAssocLookup, and duplicate column deduplication). The core fixes are sound, but there are concerns worth addressing: the onMapping parsing logic duplicates an existing helper (extractFKFieldsFromOnCondition) that should be reused; the "skip subselect" optimization's path-matching logic appears logically unreachable for typical label paths like descr; and the schema change adding @changelog to status4Nav likely produces duplicate change log entries alongside the already-tracked scalar status4 field.

PR Bot Information

Version: 1.20.37

  • File Content Strategy: Full file content
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: b16d13b8-4681-4d4e-ac7f-d69fac4ee2d2

Comment thread lib/utils/change-tracking.js
Comment thread lib/utils/change-tracking.js
Comment thread tests/bookshop/db/incidents/schema.cds
Comment thread lib/sqlite/triggers.js
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.

2 participants