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

❗ NOTICE (diff): cannot read properties of undefined on diff. #30241

Closed
rmetcalfe-msp opened this issue May 16, 2024 · 7 comments
Closed

❗ NOTICE (diff): cannot read properties of undefined on diff. #30241

rmetcalfe-msp opened this issue May 16, 2024 · 7 comments
Labels
@aws-cdk/cloudformation-diff aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. management/tracking Issues that track a subject or multiple issues p0

Comments

@rmetcalfe-msp
Copy link

rmetcalfe-msp commented May 16, 2024

Please add your +1 👍 to let us know you have encountered this


Status

Resolved

What is the issue?

The latest version of aws-cdk (v2.142.0) has broken our chalice with cdk deployment with the below error:
Cannot read properties of undefined (reading 'includes')

Overview

The change.resourceType is typed as being a string, but with this change there are cases when change.resourceType can be undefined.

Workaround

The workaround would be to use versions<v2.142.0

Resolution

The issue has been reverted and has been patched as of v2.142.1

Related issues

No response

Expected Behavior

Usual behaviour shows the cloudformation changeset, which is still the case when using v2.141.0

Creating deployment package.
Reusing existing deployment package.
Stack tools-api
Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)
Resources
[~] AWS::Serverless::Function ChaliceApp/ChaliceApp/OrchestrateModelRun OrchestrateModelRun replace
 └─ [~] CodeUri (requires replacement)
     └─ [~] .Key:
         ├─ [-] 468d08dade7d3b[52](https://github.com/org/tools-api/actions/runs/9115347347/job/25061454406#step:17:53)b777cb47a1433cf7e5721ca05b7122dc1bfee03cd135e1a7.zip
         └─ [+] 2464c7bed007b4b9ea2423157ce2a46977e17099e954eb83776fcd5ca5f4a33a.zip
...
✨  Number of stacks with differences: 1

Current Behavior

cd infrastructure
  cdk diff -c stage=$TARGET_ENV --require-approval=never
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.19/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.19/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.19/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.19/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.19/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.19/x64/lib
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
    AWS_SESSION_TOKEN: ***
    AWS_DEFAULT_REGION: ***
    TARGET_ENV: test01
/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/pandera/engines/pandas_engine.py:66: UserWarning: Using typeguard < 3. Generic types like List[TYPE], Dict[TYPE, TYPE] will only validate the first element in the collection.
  warnings.warn(
Creating deployment package.
Reusing existing deployment package.
Stack tools-api
Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)

**Cannot read properties of undefined (reading 'includes')**
Error: Process completed with exit code 1.

Result with diff --verbose:

[15:27:57] Initiated creation of changeset: arn:aws:cloudformation:eu-west-2:xxxx:changeSet/cdk-diff-change-set/cc390834-330b-4166-b695-312e208dab30; waiting for it to finish creating...
[15:27:57] Waiting for changeset cdk-diff-change-set on stack tools-api to finish creating...
[15:27:58] Changeset cdk-diff-change-set on stack tools-api is still creating
[15:28:03] Changeset cdk-diff-change-set on stack tools-api is still creating
[15:28:08] Changeset cdk-diff-change-set on stack tools-api is still creating
[15:28:13] Removing existing change set with name cdk-diff-change-set if it exists
[15:28:13] Reading cached notices from C:\Users\ReeceMetcalfe\.cdk\cache\notices.json

Cannot read properties of undefined (reading 'includes')
[15:28:14] TypeError: Cannot read properties of undefined (reading 'includes')
    at C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:30181
    at C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:19344
    at Array.forEach (<anonymous>)
    at _DifferenceCollection.forEachDifference (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:19333)
    at _enhanceChangeImpacts (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:30119)
    at refineDiffWithChangeSet (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:28333)
    at fullDiff (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:404:25024)
    at printStackDiff (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:443:166664)
    at CdkToolkit.diff (C:\Users\ReeceMetcalfe\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:443:195640)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Reproduction Steps

I'm unable to reproduce the issue with a small sample application. I will continue to try reproduce but wanted to raise here in case it might be obvious what the issue is.

CDK CLI Version

2.142.0

Framework Version

No response

Node.js Version

21.2.0

OS

Windows / Linux

Language

Python

Language Version

Python 3.9.13

Other information

No response

@rmetcalfe-msp rmetcalfe-msp added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 16, 2024
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label May 16, 2024
@scanlonp
Copy link
Contributor

Hey @rmetcalfe-msp, thanks for reporting this. We are looking into it right now. In the meantime, do you have a workaround for this issue? Pinning to v2.141.0 or using the --no-change-set flag in your diff command should avoid this.

We recently updated our diff logic to pick up some more properties from ChangeSets. I suspect thats where the bug will be. Do you have any general information about your stack that you could share? It looks like you have a severless function. Do you have any number of ssm parameters in the stack?

@scanlonp scanlonp added p0 and removed needs-triage This issue or PR still needs to be triaged. labels May 16, 2024
@rmetcalfe-msp rmetcalfe-msp changed the title aws-cdk: v2.142.0 aws-cdk: Cannot read properties of undefined with v2.142.0 May 16, 2024
@rmetcalfe-msp
Copy link
Author

@scanlonp Yes I have pinned to 2.141.0 in our deploy pipeline:
npm install -g aws-cdk@2.141.0

I've tried expanding a sample application from here which is similar to what we're using minus all of the subnet/vpc details, but still can't repeat the error unfortunately.

Sorry I can't be more help. This is the line that it appears to be failing on from the stack trace:

function _enhanceChangeImpacts(_replacements) { diff.resources.forEachDifference((logicalId, change) => { if (change.resourceType.includes("AWS::Serverless")) { return }

@bergjaak
Copy link
Contributor

We've found the root cause. The change.resourceType is typed as being a string, but with this change there are cases when change.resourceType can be undefined, as is the case here. Therefore, this change will be reverted while a fix is issued.

Thank you so much for opening this issue!

@rmetcalfe-msp
Copy link
Author

@bergjaak awesome, thanks for the prompt response and fix. Great work

@SankyRed SankyRed added management/tracking Issues that track a subject or multiple issues @aws-cdk/cloudformation-diff labels May 16, 2024
@SankyRed SankyRed changed the title aws-cdk: Cannot read properties of undefined with v2.142.0 ❗ NOTICE (diff): cannot read properties of undefined on diff. May 16, 2024
@SankyRed SankyRed pinned this issue May 16, 2024
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue May 16, 2024
danellecline added a commit to mbari-org/fastapi-yolov5 that referenced this issue May 17, 2024
@andreif
Copy link

andreif commented May 17, 2024

I have stopped using Python CDK and migrated to TypeScript one because of "undefined" errors without meaningful info that are hard to debug. Is this Python only issue or also relevant for TS?

@SankyRed
Copy link
Contributor

@andreif This was specific to CDK and not language specific. A change was made to diff in CDK v2.142.0 to include changes to properties that are only present in the change set. This introduced cases where the resource type could be undefined which resulted in an error from calling 'includes' on undefined. But, the CDK team has patched it and has been fixed in v2.142.1.

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/cloudformation-diff aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
Development

No branches or pull requests

5 participants