Skip to content

fix: customer aspect cannot add Tags if a BucketNotifications construct is present #33979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 1, 2025

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 31, 2025

The title refers to a specific case in which we discovered this, but the problem was more general.

Now that Aspects have a priority, we want to execute based on priority as the primary sort key. To make sure we don't make mistakes, the new AspectsV2 invocation (enabled with flag @aws-cdk/core.aspectStabilization: true) throws an error if it detects a violation of the strict priority execution order.

Because of the moment aspects are looked up and sorted by priority, this currently goes wrong if:

  • Aspects with a low and high priority order (say, 100 and 700) are already present in the construct tree
  • The invocation of the low-priority Aspect adds another Aspect with a priority in between 100 and 700.

The reason is that we used to look up the aspects before iterating, and iterate over them. At that point we have the list [100, 700], and we invoke both. Then, when we go around again, the new list is [100, 500, 700] with the 500 Aspect having not been invoked yet -- but also the Aspect with priority 700 already having been invoked. If we invoke 500 at that point, we would have inverted the priority order, so we fail instead.

That is undesirable: what we should have done is noticed that 500 got inserted between 100 and 700 and do that next.

Currently achieve that with the following:

  • We associate a global revision number with the entire construct tree, at the root.
  • Every time an aspect gets added, we increment that number.
  • This allows us to detect Aspect order cache validations, so we can abort what we're doing and recalculate the tree.

The system of inserting and recalculating could probably all be made more efficient, but aspects adding aspects should be relatively rare so until we have evidence that it is too expensive, this will do for now.

In the specific case reported for this, a customer Aspect with priority 10 adds a Tag Aspect (priority 200) while the BucketNotification construct also adds an Aspect on itself with priority 500. The mere presence of this BucketNotification construct with its self-added Aspect prevents any Aspect from adding tags.

Closes #33943.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@rix0rrr rix0rrr requested a review from a team as a code owner March 31, 2025 12:05
@aws-cdk-automation aws-cdk-automation requested a review from a team March 31, 2025 12:05
@github-actions github-actions bot added bug This issue is a bug. p2 labels Mar 31, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 31, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@rix0rrr rix0rrr force-pushed the huijbers/aspect-in-the-middle branch from 04adfca to 4ee1dbf Compare March 31, 2025 12:07
@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Mar 31, 2025
@rix0rrr rix0rrr changed the title fix: Aspect cannot add Tags if a BucketNotifications construct is present fix: aspect cannot add Tags if a BucketNotifications construct is present Mar 31, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 31, 2025 12:09

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@rix0rrr rix0rrr changed the title fix: aspect cannot add Tags if a BucketNotifications construct is present fix: customer aspect cannot add Tags if a BucketNotifications construct is present Mar 31, 2025
Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.43%. Comparing base (929ab3a) to head (61ba1fd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #33979      +/-   ##
==========================================
+ Coverage   82.39%   82.43%   +0.03%     
==========================================
  Files         120      120              
  Lines        6960     6975      +15     
  Branches     1175     1178       +3     
==========================================
+ Hits         5735     5750      +15     
  Misses       1120     1120              
  Partials      105      105              
Flag Coverage Δ
suite.unit 82.43% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.43% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Mar 31, 2025
@shikha372 shikha372 added the skip-abstractions-board signal to automated workflow to skip adding to project board label Mar 31, 2025
Copy link
Contributor

mergify bot commented Apr 1, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 61ba1fd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Apr 1, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2cff67e into main Apr 1, 2025
20 checks passed
@mergify mergify bot deleted the huijbers/aspect-in-the-middle branch April 1, 2025 13:23
Copy link
Contributor

github-actions bot commented Apr 1, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exempt-integ-test The PR linter will not require integ test changes skip-abstractions-board signal to automated workflow to skip adding to project board
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding an aspect to Bucket with S3 notifications leads to an error
4 participants