Fix: Retain attachment uploadStatus on draft activation - #572
Open
akgarg06 wants to merge 1 commit into
Open
Conversation
Contributor
|
👋 Hi — I'm PR Bot, your SAP code review assistant. I'll automatically review your pull requests for code quality, security, and SAP compliance. Get an overview of what I do → What I do
Key commands
Configure me for your teamCreate {
"$schema": "https://devops-insights-pr-bot.cfapps.eu10-004.hana.ondemand.com/schema/pull_request_bot.json",
"features": {
"control_panel": false,
"summarize": {
"auto_generate_summary": true,
"auto_insert_summary": true,
"auto_run_on_draft_pr": true,
"use_custom_summarize_prompt": false,
"use_custom_summarize_output_template": false,
"excluded_paths": [],
"auto_exclude_authors": []
},
"review": {
"auto_generate_review": true,
"auto_run_on_draft_pr": false,
"use_custom_review_focus": false,
"excluded_paths": [],
"auto_exclude_authors": []
},
"sonar_fix": {
"enable": true,
"excluded_rules": []
},
"pipeline_fix": {
"enable": true
}
},
"excluded_paths": []
}*This introduction message will be shown to you only once, you will not see it in future PRs. |
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.
Describe your changes
Problem
When a draft-enabled entity with @SDM.Attachments compositions is activated (draft → active), every attachment's uploadStatus was reset to the CDS default 'uploading' instead of keeping its real value (e.g. Success).
Impact:
UI shows attachments stuck on "Uploading" after save
Downloads are blocked (SDM only serves files in Success state)
Affects all CAP apps using @SDM.Attachments on draft-enabled entities
Root cause
uploadStatus is @readonly with default 'uploading'. CAP strips @readonly fields from the payload, so on activation the active rows get the DB default. The existing preserve/restore logic only covered normal CREATE — there was no handler for DraftService.EVENT_DRAFT_SAVE, so the draft-activation path fell through.
Fix
Added @Before/@after(EVENT_DRAFT_SAVE) handlers in SDMCreateAttachmentsHandler:
@before — captures each attachment's ID + uploadStatus from the draft rows (while they still exist) into a ThreadLocal.
@after — writes those values back onto the newly activated active rows via saveUploadStatusToAttachment.
Recursively walks the composition tree, so attachments at any nesting depth (e.g. Books → Chapters → attachments) are covered — not just direct compositions. Depth-bounded and wrapped in try/catch so it never blocks the save.
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Upload Screenshots/lists of the scenarios tested