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

v1.103.1 -> v1.104.0 upgrade breaks Python code using an IntEnum value where int is expected #4662

Closed
1 task done
anentropic opened this issue Oct 14, 2024 · 2 comments
Closed
1 task done
Labels
bug This issue is a bug. closed-for-staleness needs-triage This issue or PR still needs to be triaged. 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

@anentropic
Copy link

anentropic commented Oct 14, 2024

Describe the bug

I have Python CDK code like this:

from enum import IntEnum
from aws_cdk import aws_ecs as ecs

class FargateCpu(IntEnum):
    QUARTER = 256  # 0.25 vCPU
    HALF = 512
    ONE = 1024
    TWO = 2048
    FOUR = 4096
    EIGHT = 8192
    SIXTEEN = 16384

task = ecs.FargateTaskDefinition(
    self,
    "<Task Name>",
    cpu=FargateCpu.ONE,
    ...
)

After upgrading dependency packages:

Update jsii 1.103.1 -> 1.104.0 successful

...the code above has started breaking with AttributeError: __jsii_type__

if I amend this line: cpu=FargateCpu.ONE.value then it works again

but that should not be necessary

Regression Issue

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

Expected Behavior

IntEnum is a true subclass of int

so this is not just a duck-typing problem but a failure to recognise subtype

it should be valid to use IntEnum member anywhere that int is expected

Current Behavior

infra/constructs/containers.py:154: in __init__
    self.tasks[task_name] = task = ecs.FargateTaskDefinition(
.venv/lib/python3.11/site-packages/jsii/_runtime.py:118: in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
.venv/lib/python3.11/site-packages/aws_cdk/aws_ecs/__init__.py:41433: in __init__
    jsii.create(self.__class__, self, [scope, id, props])
.venv/lib/python3.11/site-packages/jsii/_kernel/__init__.py:334: in create
    response = self.provider.create(
.venv/lib/python3.11/site-packages/jsii/_kernel/providers/process.py:365: in create
    return self._process.send(request, CreateResponse)
.venv/lib/python3.11/site-packages/jsii/_kernel/providers/process.py:323: in send
    req_dict = self._serializer.unstructure(request)
.venv/lib/python3.11/site-packages/cattrs/converters.py:300: in unstructure
    return self._unstructure_func.dispatch(
.venv/lib/python3.11/site-packages/jsii/_kernel/providers/process.py:107: in unstructurer
    unstructured = asdict(value)
.venv/lib/python3.11/site-packages/cattrs/converters.py:588: in unstructure_attrs_asdict
    rv[name] = dispatch(a.type or v.__class__)(v)
.venv/lib/python3.11/site-packages/cattrs/gen/__init__.py:1048: in unstructure_iterable
    return _seq_cl(_hook(i) for i in iterable)
.venv/lib/python3.11/site-packages/cattrs/gen/__init__.py:1048: in <genexpr>
    return _seq_cl(_hook(i) for i in iterable)
.venv/lib/python3.11/site-packages/cattrs/converters.py:300: in unstructure
    return self._unstructure_func.dispatch(
:2: in unstructure_mapping
    ???
:2: in <genexpr>
    ???
.venv/lib/python3.11/site-packages/cattrs/converters.py:300: in unstructure
    return self._unstructure_func.dispatch(
:2: in unstructure_mapping
    ???
:2: in <genexpr>
    ???
.venv/lib/python3.11/site-packages/cattrs/converters.py:300: in unstructure
    return self._unstructure_func.dispatch(
:2: in unstructure_mapping
    ???
:2: in <genexpr>
    ???
.venv/lib/python3.11/site-packages/cattrs/converters.py:300: in unstructure
    return self._unstructure_func.dispatch(
.venv/lib/python3.11/site-packages/jsii/_kernel/providers/process.py:126: in _unstructure_enum
    return {"$jsii.enum": f"{member.__class__.__jsii_type__}/{member.value}"}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <enum 'FargateCpu'>, name = '__jsii_type__'

    def __getattr__(cls, name):
        """
        Return the enum member matching `name`
    
        We use __getattr__ instead of descriptors or inserting into the enum
        class' __dict__ in order to support `name` and `value` being both
        properties for enum members (which live in the class' __dict__) and
        enum members themselves.
        """
        if _is_dunder(name):
>           raise AttributeError(name)
E           AttributeError: __jsii_type__

Reproduction Steps

see above

Possible Solution

No response

Additional Information/Context

I have guessed this is a JSII issue rather than something in CDK lib.

SDK version used

1.104.0

Environment details (OS name and version, etc.)

macos 14.6.1, nodejs v20.15.1, Python 3.11

@anentropic anentropic added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 14, 2024
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Oct 14, 2024
@otaviomacedo
Copy link
Contributor

Hi, @anentropic. Can you provide more details on how to reproduce this issue? I have created a simple Python CDK app with the code above and it works as expected.

@mrgrain mrgrain added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 16, 2024
Copy link
Contributor

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 26, 2024
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 needs-triage This issue or PR still needs to be triaged. 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

3 participants