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

aws_cdk.assertions.Annotations.find_error: Instead of emitting none, shows KeyError: 'aws-cdk-lib.cloud_assembly_schema.MetadataEntry #33211

Closed
1 task done
pwrmiller opened this issue Jan 28, 2025 · 3 comments
Assignees
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package bug This issue is a bug. p3 potential-regression Marking this issue as a potential regression to be checked by team member response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@pwrmiller
Copy link

Describe the bug

In previous versions of CDK, aws_cdk.assertions.Annotations.from_stack worked, in newer versions of CDK it is broken (in Python 3.12)

Calls to Annotations similar to

    Annotations.from_stack(mystack).find_error(
        "*",
        "some-error",
    )

Now, the find_error raises:

Traceback (most recent call last):

  File "aws_cdk/assertions/__init__.py", line 725, in find_error
    return typing.cast(typing.List[_SynthesisMessage_b3ae3c62], jsii.invoke(self, "findError", [construct_path, message]))
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_kernel/__init__.py", line 149, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_kernel/__init__.py", line 137, in _recursize_dereference
    return [_recursize_dereference(kernel, i) for i in d]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_kernel/__init__.py", line 139, in _recursize_dereference
    return _reference_map.resolve_reference(kernel, d)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_reference_map.py", line 122, in resolve
    python_name: kernel.get(remote_struct, jsii_name)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_kernel/__init__.py", line 149, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_kernel/__init__.py", line 139, in _recursize_dereference
    return _reference_map.resolve_reference(kernel, d)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_reference_map.py", line 129, in resolve
    return InterfaceDynamicProxy(self.build_interface_proxies_for_ref(ref))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jsii/_reference_map.py", line 137, in build_interface_proxies_for_ref
    ifaces = [_interfaces[fqn] for fqn in ref.interfaces or []]
              ~~~~~~~~~~~^^^^^
KeyError: 'aws-cdk-lib.cloud_assembly_schema.MetadataEntry'

I suspect that this is broken after #32998 since this is a relatively recent change impacting MetadataEntry.

Running the find_error on a message that does not exist succeeds (returns an empty array). It is interesting that has_error works correctly, but find_error appears to be broken.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

I expect both find_error and has_error to work correctly.

Current Behavior

find_error now raises a KeyError related to MetadataEntry, see above

Reproduction Steps

from aws_cdk import App, Stack, Annotations
import aws_cdk.assertions

if __name__ == "__main__":
    app = App()
    stack = Stack(app, "MyStack")
    Annotations.of(stack).add_error("oh no")

    assertions = aws_cdk.assertions.Annotations.from_stack(stack).find_error(
        "*",
        "oh no"
    )
   # raises KeyError: 'aws-cdk-lib.cloud_assembly_schema.MetadataEntry', but we expect this to not raise anything.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.177.0

Framework Version

aws-cdk-lib 2.177.0

Node.js Version

v20.18.1

OS

Darwin DYFXL2QQK9 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64

Language

Python

Language Version

3.12

Other information

No response

@pwrmiller pwrmiller added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 28, 2025
@github-actions github-actions bot added potential-regression Marking this issue as a potential regression to be checked by team member @aws-cdk/assertions Related to the @aws-cdk/assertv2 package labels Jan 28, 2025
@pahud pahud self-assigned this Jan 28, 2025
@pahud pahud added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Jan 28, 2025
@pahud
Copy link
Contributor

pahud commented Jan 28, 2025

Hi

I was not able to reproduce this issue.

My code app.py

from aws_cdk import App, Stack, Annotations
import aws_cdk.assertions

if __name__ == "__main__":
    app = App()
    stack = Stack(app, "MyStack")
    Annotations.of(stack).add_error("oh no")

    assertions = aws_cdk.assertions.Annotations.from_stack(stack).find_error(
        "*",
        "oh no"
    )
% npx cdk synth
[Error at /MyStack] oh no
Found errors
% npx cdk --version
2.177.0 (build b396961)
% grep cdk requirements.txt 
aws-cdk-lib==2.177.0

Can you init a fresh environment and let me know if the issue persists?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels Jan 28, 2025
@pwrmiller
Copy link
Author

Blame cosmic rays, I guess. A fresh virtual environment resolved the issue. Thanks for the prompt response.

Copy link

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 Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package bug This issue is a bug. p3 potential-regression Marking this issue as a potential regression to be checked by team member response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants