Fix issue in discarding newly created entities which has multi-level of nested children#520
Open
yashmeet29 wants to merge 2 commits into
Open
Fix issue in discarding newly created entities which has multi-level of nested children#520yashmeet29 wants to merge 2 commits into
yashmeet29 wants to merge 2 commits into
Conversation
…of nested children
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
Fix: NoSuchElementException during draft discard when attachments exist on a grandchild composition entity
handleDraftDiscardForLinks was calling getAttachmentPathMapping on the root entity being discarded. This method traverses nested compositions to find attachment entities, but buildEntityPath always used the direct child entity as the namespace when constructing the map key — regardless of how deep the actual attachment entity lived.
For example, given the structure:
SourcingEventsServiceEntity
└── TeamAddinsServiceEntity (direct child, no attachments)
└── TeamsServiceEntity
└── attachments (grandchild)
buildEntityPath produced SourcingEventService.TeamAddinsServiceEntity.attachments instead of SourcingEventService.TeamsServiceEntity.attachments. When revertLinksForComposition appended _drafts and called model.findEntity(...), the entity was not found, causing NoSuchElementException.
The fix:
Added getDirectAttachmentPathMapping in AttachmentsHandlerUtils that only processes direct sap.attachments.Attachments compositions on the root entity — no nested traversal.
Updated handleDraftDiscardForLinks to use getDirectAttachmentPathMapping for Path 1 (root entity direct attachments).
Nested attachment handling is already correctly implemented in the existing revertNestedEntityLinks → processNestedEntityComposition path (Path 2), which calls getAttachmentPathMapping on each direct child individually — meaning targetEntity always equals the entity where the attachment actually lives.
Additionally fixed unsafe Optional.get() calls without isPresent() checks in DBQuery.getuploadStatusForAttachment.
Any documentation
The issue only manifests when attachments are defined on a grandchild or deeper composition of the draft-cancelled entity. Applications where attachments are directly on the first-level child (like the standard demo app) are unaffected.
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Upload Screenshots/lists of the scenarios tested
Single-tenant Integration tests: https://github.com/cap-java/sdm/actions/runs/28505618401
Multi-tenant Integration tests: https://github.com/cap-java/sdm/actions/runs/28516956119