Skip to content

Add content overwrite support#415

Merged
KoblerS merged 7 commits intomainfrom
add-content-overwrite-support
Apr 2, 2026
Merged

Add content overwrite support#415
KoblerS merged 7 commits intomainfrom
add-content-overwrite-support

Conversation

@KoblerS
Copy link
Copy Markdown
Member

@KoblerS KoblerS commented Apr 2, 2026

Add Content Overwrite Support for Attachments

New Feature

✨ Introduces configurable content overwrite behavior for the @cap-js/attachments plugin. By default, attachment content is protected from being overwritten (returning a 409 Conflict error). Users can now opt-in to allow content overwrites on a per-composition basis using the @Capabilities.UpdateRestrictions.NonUpdateableProperties annotation.

Changes

  • db/index.cds: Added default annotation @Capabilities.UpdateRestrictions.NonUpdateableProperties: [content] to the Attachments aspect, preventing content overwrites out of the box.

  • srv/basic.js: Introduced the _isContentUpdateRestricted() helper method that inspects the @Capabilities.UpdateRestrictions.NonUpdateableProperties annotation on an attachment entity. The existing 409-conflict check in put() is now gated behind this helper, so the restriction is only enforced when the annotation includes content.

  • srv/aws-s3.js, srv/azure-blob-storage.js, srv/gcp.js: Updated the put() upload guard in all three storage backends to call _isContentUpdateRestricted() before checking for an existing file, enabling overwrite behavior when the annotation allows it.

  • tests/incidents-app/db/attachments.cds: Added a new overwritableAttachments composition annotated with @Capabilities.UpdateRestrictions.NonUpdateableProperties: [] for testing the opt-in overwrite scenario.

  • tests/integration/attachments-non-draft.test.js: Added an integration test that verifies content can be successfully overwritten when the annotation is set to an empty array.

  • README.md: Added a new Allow Overwriting Attachment Content section documenting the feature, including a CDS example and a note about runtime evaluation across storage backends. Also updated the Table of Contents.

  • CHANGELOG.md: Documented the new feature under version 3.11.0.

  • package.json: Bumped version from 3.10.0 to 3.11.0.

  • 🔄 Regenerate and Update Summary

📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

PR Bot Information

Version: 1.19.15 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Output Template: Default Template
  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: 5ade5400-2e74-11f1-9f6b-5a4534e5aad0
  • Event Trigger: pull_request.opened

@KoblerS KoblerS self-assigned this Apr 2, 2026
@KoblerS KoblerS marked this pull request as ready for review April 2, 2026 09:22
@KoblerS KoblerS requested a review from a team as a code owner April 2, 2026 09:22
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 introduces a clean mechanism to allow content overwriting via annotation override, with consistent implementation across all storage backends (DB, S3, Azure, GCP). Three issues were identified: a subtle null-guard imprecision in _isContentUpdateRestricted, a SELECT.one bug that can miss existing content when multiple attachment IDs are checked in bulk, and a test that asserts the overwrite HTTP status but never validates that the stored content actually changed.

PR Bot Information

Version: 1.19.15 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • File Content Strategy: Full file content
  • Correlation ID: 8a5602e0-2e75-11f1-8f5a-b621bca23555
  • Event Trigger: pull_request.ready_for_review
  • LLM: anthropic--claude-4.6-sonnet

Co-authored-by: Marten Schiwek <marten.schiwek@sap.com>
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 introduces content overwrite support via @Capabilities.UpdateRestrictions.NonUpdateableProperties, which is well-structured across all storage backends (DB, S3, Azure, GCP). The core logic in _isContentUpdateRestricted is sound and the test coverage for both the restricted and permissive cases is thorough. The three issues flagged are: an empty ### Fixed changelog section, a misleading inline comment about the default restriction behavior, and a potential mid-stream failure scenario on object stores when overwriting (no explicit cleanup of the old blob before the new upload begins). Please address these before merging.

PR Bot Information

Version: 1.19.15 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content
  • Correlation ID: 5ade5400-2e74-11f1-9f6b-5a4534e5aad0


- Support for controlling content overwrite behavior via `@Capabilities.UpdateRestrictions.NonUpdateableProperties`. By default, `content` is listed as non-updateable, preventing overwrites with a `409` error. Setting the annotation to an empty array (`[]`) on a specific attachment composition allows content to be overwritten.

### Fixed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Empty ### Fixed section in CHANGELOG entry

The ### Fixed section for v3.11.0 has no content, leaving an empty heading. Either add a relevant fix entry or remove the section entirely.

Suggested change
### Fixed
## Version 3.11.0
### Added
- Support for controlling content overwrite behavior via `@Capabilities.UpdateRestrictions.NonUpdateableProperties`. By default, `content` is listed as non-updateable, preventing overwrites with a `409` error. Setting the annotation to an empty array (`[]`) on a specific attachment composition allows content to be overwritten.

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

@KoblerS KoblerS merged commit 51ae0e4 into main Apr 2, 2026
49 of 53 checks passed
@KoblerS KoblerS deleted the add-content-overwrite-support branch April 2, 2026 11:27
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.

3 participants