Skip to content
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

fix(core): overrideLogicalId validation #29708

Closed
wants to merge 2 commits into from

Conversation

nmussy
Copy link
Contributor

@nmussy nmussy commented Apr 3, 2024

Issue # (if applicable)

Closes #29701

Reason for this change

Calling overrideLogicalId on a Construct with an invalid logical ID (docs) would not throw an error at synthesis time. CloudFormation would

Description of changes

  • Validate overrideLogicalId (must not be empty, must not be over 255 characters, must match /^[A-Za-z0-9]+$/
  • Document exceptions with @error JSDoc tags

Description of how you validated changes

I've added unit tests, integration tests should not be necessary

Checklist


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

@github-actions github-actions bot added distinguished-contributor [Pilot] contributed 50+ PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2 labels Apr 3, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team April 3, 2024 19:03
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.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@nmussy
Copy link
Contributor Author

nmussy commented Apr 3, 2024

Exemption Request: This is just a synth time check, CloudFormation is already failing if unhappy with the logical ID

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Apr 3, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@nmussy nmussy marked this pull request as ready for review April 3, 2024 19:38
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 3, 2024
@TheRealAmazonKendra TheRealAmazonKendra added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Apr 8, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 8, 2024 22:19

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

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

I'm hesitant to accept this but am open to conversation about it. If CloudFormation updates their requirements here, it would create more manual work on our end. Is the error message unclear enough at deploy time that this provides a major quality of life improvement for users?

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 8, 2024
@nmussy
Copy link
Contributor Author

nmussy commented Apr 9, 2024

The CloudFormation deploy time message is absolutely clear about this issue, this is a duplicated synth time check

The main issue is the difference in how the CDK resolves regular construct generated logical IDs vs overrides. The IDs provided to the constructor are slugified, but not the overrides:

new cdk.CfnOutput(this, 'Invalid construct name', { 
  value: 'value', 
});

new cdk.CfnOutput(this, 'Output', { 
  value: 'value', 
}).overrideLogicalId('Another invalid construct name');
$ npm run cdk synth

Outputs:
  Invalidconstructname:
    Value: value
  Another invalid construct name:
    Value: value

I don't think changing this behavior to also slugify the override is warranted, to leave the escape hatch as is. Giving the user an early warning is probably best.

This PR would also prevent an issue like #29700 from reoccurring. An integration test would have caught it, but a unit test would have been sufficient with this change.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@nmussy
Copy link
Contributor Author

nmussy commented Apr 30, 2024

@TheRealAmazonKendra Bump

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label May 7, 2024
@nmussy
Copy link
Contributor Author

nmussy commented May 7, 2024

@TheRealAmazonKendra Bunping again 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/small Small work item – less than a day of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core: missing logical ID override validation
3 participants