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

type object 'InvokeOptions' has no attribute 'merge' ERROR #3269

Closed
Nidhal-Hajjej opened this issue May 8, 2024 · 9 comments
Closed

type object 'InvokeOptions' has no attribute 'merge' ERROR #3269

Nidhal-Hajjej opened this issue May 8, 2024 · 9 comments
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@Nidhal-Hajjej
Copy link

Nidhal-Hajjej commented May 8, 2024

What happened?

i am using pulumi for a fastapi project ComworkCloud in which i want to create_bucket for azure Driver. My function is to create an azure storage account and storage container and export the endpoint for the container and the access key. I used azure-native.storage.listStorageAccountKeys to get that access key but unfortunately i got this error:

File "/usr/local/lib/python3.9/site-packages/pulumi_azure_native/storage/list_storage_account_keys.py", line 67, in list_storage_account_keys
opts = pulumi.InvokeOptions.merge(_utilities.get_invoke_opts_defaults(), opts)
AttributeError: type object 'InvokeOptions' has no attribute 'merge'

Example

here is my function:

def create_bucket(self, user_email, bucket_id, hashed_bucket_name, region, bucket_type):
    def create_pulumi_program():
        resource_group_name = f"rg-{hashed_bucket_name}"
        resource_group = resources.ResourceGroup(
            "my-Resource-Group", location=region, resource_group_name=resource_group_name)

        # Create an Azure storage account
        storage_account = storage.StorageAccount(
            "storage",
            resource_group_name=resource_group.name,
            sku=storage.SkuArgs(
                name=storage.SkuName.STANDARD_LRS),
            allow_blob_public_access=True,
            location=region,
            # allow_shared_key_access=True,
            # account_tier="Standard",
            kind=storage.Kind.STORAGE_V2
        )
        # Create a storage container
        storage_container = storage.BlobContainer(
            hashed_bucket_name,
            resource_group_name=resource_group.name,
            account_name=storage_account.name)

        storage_keys = pulumi.Output.all(resource_group.name, storage_account.name).apply(
            lambda args: pulumi.Output.secret(storage.list_storage_account_keys(args[0], args[1]).apply(
                lambda account_keys: account_keys.keys[0].value)))

        pulumi.export("access_key", storage_keys)

        # Construct the Blob Container URL
        blob_container_url = pulumi.Output.concat(
            "https://",
            [storage_account.name](http: // storage_account.name /) ,
            ".[blob.core.windows.net/](http://blob.core.windows.net/)",
            [storage_container.name](http: // storage_container.name /)
        )
        pulumi.export("endpoint", blob_container_url)
        pulumi.export("secret_key", "N/A")


print('Creating stack')
stack = auto.create_or_select_stack(stack_name=hashed_bucket_name,
                                    project_name="test-bucket",
                                    program=create_pulumi_program)

stack.set_config("azure-native:environment", auto.ConfigValue("public"))
stack.set_config("azure-native:clientId", auto.ConfigValue(_azure_client_id))
stack.set_config("azure-native:clientSecret",
                 auto.ConfigValue(_azure_client_secret, secret=True))
stack.set_config("azure-native:tenantId", auto.ConfigValue(_azure_tenant_id))
stack.set_config("azure-native:subscriptionId",
                 auto.ConfigValue(_azure_subscription_id))
stack.set_config("azure-native:location", auto.ConfigValue(region))

up_res = stack.up()

print('Stack created successfully.')

return {
    "endpoint": up_res.outputs.get("endpoint").value,
    "name": hashed_bucket_name,
    "user_id": user_email,
    # "access_key": access_key,
    "access_key": up_res.outputs.get("access_key").value,
    "secret_key": "N/A",
    "status": "active"
}

Output of pulumi about

I am not creating a pulumi project.
This a fastapi project with python version = 3.9.16 and pulumi_azure_native == 2.30.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@Nidhal-Hajjej Nidhal-Hajjej added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 8, 2024
@thomas11
Copy link
Contributor

thomas11 commented May 10, 2024

Hi @Nidhal-Hajjej, I'm not sure yet what the problem is here. However, I think your code can be simplified, and maybe this could even fix this issue if it's related to Pulumi's Output handling.

Instead of calling storage.list_storage_account_keys inside an apply

pulumi.Output.all([resource_group.name](http://resource_group.name/), [storage_account.name](http://storage_account.name/)).apply(
lambda args: pulumi.Output.secret(storage.list_storage_account_keys(args[0], args[1])

you can use its output form:

storage.list_storage_account_keys_output(storage_account.name, resource_group.name)

You might also have switched the resource group and account name arguments, based on our API docs.

Could you try if that helps at all?

@thomas11 thomas11 added awaiting-feedback and removed needs-triage Needs attention from the triage team labels May 10, 2024
@Nidhal-Hajjej
Copy link
Author

Nidhal-Hajjej commented May 10, 2024 via email

@thomas11
Copy link
Contributor

thomas11 commented May 11, 2024

Hi @Nidhal-Hajjej, unfortunately I don't know FastAPI. But wherever you write the Pulumi code, could you try my suggestions to use storage.list_storage_account_keys_output and check the order of arguments?

@Nidhal-Hajjej
Copy link
Author

Nidhal-Hajjej commented May 11, 2024

Hi @thomas11, i checked the solution you provided and i checked the right order of arguments but unfortunately i got the same error:
error: python inline source runtime error: type object 'InvokeOptions' has no attribute 'merge' Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pulumi/automation/_server.py", line 69, in Run loop.run_until_complete(run_in_stack(self.program)) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 126, in run_in_stack await run_pulumi_func(lambda: Stack(func)) File "/usr/local/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 51, in run_pulumi_func await wait_for_rpcs() File "/usr/local/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 110, in wait_for_rpcs raise exception File "/usr/local/lib/python3.9/site-packages/pulumi/output.py", line 169, in run value = await self._future File "/usr/local/lib/python3.9/site-packages/pulumi/output.py", line 194, in run transformed: Input[U] = func(value) File "/usr/local/lib/python3.9/site-packages/pulumi_azure_native/_utilities.py", line 245, in <lambda> }).apply(lambda resolved_args: func(*resolved_args['args'], File "/usr/local/lib/python3.9/site-packages/pulumi_azure_native/storage/list_storage_account_keys.py", line 67, in list_storage_account_keys opts = pulumi.InvokeOptions.merge(_utilities.get_invoke_opts_defaults(), opts) AttributeError: type object 'InvokeOptions' has no attribute 'merge'
pulumi about for my running container output is:
`
CLI
Version 3.115.2
Go Version go1.22.2
Go Compiler gc

Host
OS debian
Version 11.9
Arch x86_64

This project is written in python: executable='/usr/local/bin/python3' version='3.9.16'
`
Thanks in advance.

@pulumi-bot pulumi-bot added needs-triage Needs attention from the triage team and removed awaiting-feedback labels May 11, 2024
@thomas11
Copy link
Contributor

Hi @Nidhal-Hajjej, can you determine the version of the pulumi Python package that's being used? Something like pip list or pip3 list should show it, depending on how FastAPI manages Python packages.

Can you also share your latest program, after your changes?

@thomas11 thomas11 added awaiting-feedback and removed needs-triage Needs attention from the triage team labels May 13, 2024
@Nidhal-Hajjej
Copy link
Author

image

@thomas11
Copy link
Contributor

Thank you @Nidhal-Hajjej ! That could be the issue. pulumi 3.33.1 is about two years old, and the missing merge function was added around that time. Latest is 3.116.0. Could you try to upgrade?

@mikhailshilkov
Copy link
Member

@Nidhal-Hajjej Are you able to upgrade your pulumi version? I'm pretty sure @thomas11 is right and a later version of the core library should solve your issue.

@Nidhal-Hajjej
Copy link
Author

Dear @thomas11,
your solution resolved the issue.
Thank you for your help.

@thomas11 thomas11 added resolution/fixed This issue was fixed and removed awaiting-feedback labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

4 participants