Skip to content

(aws-rds): "DatabaseSecret" is incompatible with protocol "ISecret" #27852

Closed as not planned
@anentropic

Description

@anentropic

Describe the bug

I get a type error when passing DatabaseSecret in places where a DatabaseSecret is expected

Expected Behavior

rds.Credentials.from_secret(db_secret)

docstring for from_secret says "Creates Credentials from an existing Secrets Manager Secret (or DatabaseSecret)."

so I should be able to pass a DatabaseSecret without getting a type error

Current Behavior

Error from Pyright in VS Code:

Argument of type "DatabaseSecret" cannot be assigned to parameter "secret" of type "ISecret" in function "from_secret"
"DatabaseSecret" is incompatible with protocol "ISecret"
"secret_value_from_json" is an incompatible type
Type "(json_field: str) -> SecretValue" cannot be assigned to type "(key: str) -> SecretValue"
Parameter name mismatch: "key" versus "json_field"PylancereportGeneralTypeIssues

Reproduction Steps

from aws_cdk import (
    Stack,
    aws_ec2 as ec2,
    aws_rds as rds,
)

class MyStack(Stack):
    def __init__(
        self,
        scope: Construct,
        id: str,
        db_name: str,
        **kwargs,
    ):
        super().__init__(scope, id, **kwargs)
        vpc = ec2.Vpc.from_lookup(self, "VPC", is_default=True)
        db_admin = rds.DatabaseSecret(
            self,
            "DB Connection Secret",
            username="admin",
            dbname=db_name,
        )
        database = rds.DatabaseInstance(
            self,
            "MySQL",
            engine=rds.DatabaseInstanceEngine.mysql(
                version=rds.MysqlEngineVersion.VER_8_0
            ),
            vpc=vpc,
            credentials=rds.Credentials.from_secret(db_admin),  # error here
        )
        database.add_rotation_multi_user(
            "DB Credential Rotation",
            secret=db_admin,  # error here
        )

Possible Solution

I guess make the naming consistent with the interface it's supposed to implement

Additional Information/Context

No response

CDK CLI Version

2.104.0 (build 3b99abe)

Framework Version

2.102.0

Node.js Version

v18.18.0

OS

macOS 14.1

Language

Python

Language Version

3.11

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-rdsRelated to Amazon Relational DatabasebugThis issue is a bug.effort/mediumMedium work item – several days of effortlanguage/pythonRelated to Python bindingsp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions