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

ContainerApp connection creation fails for PostgreSQL when default output is not json #7135

Closed
dbroeglin opened this issue Dec 30, 2023 · 1 comment · Fixed by #7225
Closed
Labels
Auto-Assign Auto assign by bot bug This issue requires a change to an existing behavior in the product in order to be resolved. ContainerApp Service Attention This issue is responsible by Azure service team. Subscription

Comments

@dbroeglin
Copy link
Member

Describe the bug

If the default output type for AZCLI is not JSON (defined in az cli config file), creating Container App connections for PostgreSQL flexible server fails.

Related command

az containerapp connection create postgres-flexible \
            --connection postgresql  \
            --name ca-pi-test-006 \
            --resource-group rg-pi-test-006 \
            --target-resource-group rg-pi-test-006 \
            --server pg-pi-test-006 \
            --database pi_development \
            --client-type ruby \
            --system-identity \
            --container ca-pi-test-006\
            --customized-keys AZURE_POSTGRESQL_CONNECTIONSTRING=DATABASE_URL

Errors

Unexpected error:

The installed extension 'serviceconnector-passwordless' is in preview.
The command failed with an unexpected error. Here is the traceback:
'bytes' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/command_modules/serviceconnector/custom.py", line 317, in connection_create
    return azext_custom.connection_create_ext(cmd, client, connection_name, client_type,
  File "/home/dominique/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/custom.py", line 31, in connection_create_ext
    return connection_create_func(cmd, client, connection_name, client_type,
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/command_modules/serviceconnector/custom.py", line 462, in connection_create_func
    new_auth_info = enable_mi_for_db_linker(
  File "/home/dominique/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/_credential_free.py", line 62, in enable_mi_for_db_linker
    target_handler = getTargetHandler(
  File "/home/dominique/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/_credential_free.py", line 157, in getTargetHandler
    return PostgresFlexHandler(cmd, target_id, target_type, auth_info, connection_name, skip_prompt)
  File "/home/dominique/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/_credential_free.py", line 632, in __init__
    super().__init__(cmd, target_id, target_type,
  File "/home/dominique/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/_credential_free.py", line 176, in __init__
    self.login_username = run_cli_cmd(
AttributeError: 'bytes' object has no attribute 'get'

Issue script & Debug output

Not necessary as the stack is clear about the issue.

Expected behavior

It should work even if the user set a different output type in his config.
It works when removing the configuration from ~/.azure/config

Environment Summary

Tested in Cloud Shell:

azure-cli                         2.55.0

core                              2.55.0
telemetry                          1.1.0

Extensions:
ai-examples                        0.2.5
ml                                2.22.0
serviceconnector-passwordless              0.3.13
ssh                                2.0.2

Dependencies:
msal                            1.24.0b2
azure-mgmt-resource             23.1.0b2

Python location '/usr/bin/python3.9'
Extensions directory '/home/dominique/.azure/cliextensions'
Extensions system directory '/usr/lib/python3.9/site-packages/azure-cli-extensions'

Python (Linux) 3.9.14 (main, Oct 12 2023, 19:48:32) 
[GCC 11.2.0]

Additional context

Seems that the issue is comes from lines like:

self.login_username = run_cli_cmd(`az account show').get("user")

run_cli_cmd will try to parse the command's output as JSON and revert to returning the bytes if it fails.

@dbroeglin dbroeglin added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Dec 30, 2023
@yonzhan
Copy link
Collaborator

yonzhan commented Dec 30, 2023

Thank you for opening this issue, we will look into it.

@microsoft-github-policy-service microsoft-github-policy-service bot added Auto-Assign Auto assign by bot ContainerApp Service Attention This issue is responsible by Azure service team. Subscription labels Dec 30, 2023
dbroeglin added a commit to dbroeglin/azure-cli-extensions that referenced this issue Dec 30, 2023
  Issue is fixed for that particular command. But the issue might still
  be there for other commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot bug This issue requires a change to an existing behavior in the product in order to be resolved. ContainerApp Service Attention This issue is responsible by Azure service team. Subscription
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants