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

rdbms-connect execute does not show output when using input from file (but it does using a direct query) #6359

Open
jmservera opened this issue Jun 2, 2023 · 5 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. MySQL Service Attention This issue is responsible by Azure service team.

Comments

@jmservera
Copy link

Describe the bug

When running the command az mysql flexible-server execute using the file input option -f query.sql, it does not show the output of the query as it does when using the query option -q "SELECT 'HELLO WORLD'" because the code that shows the output is not present in the _connect_execute_file method:

Related command

az mysql flexible-server execute

Errors

NAME -f /tmp/test.sql --database-name 'airsonic'
Running sql file '/tmp/test.sql'...
Successfully executed the file.
Closed the connection to airsdeleteme

Issue script & Debug output

cli.knack.cli: Command arguments: ['mysql', 'flexible-server', 'execute', '--admin-user', '', '--admin-password', '', '--name', 'airsdeleteme', '-f', '/tmp/test.sql', '--database-name', 'airsonic', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7faa3c90d480>, <function OutputProducer.on_global_arguments at 0x7faa3c8200d0>, <function CLIQuery.on_global_arguments at 0x7faa3c8512d0>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'mysql': ['azure.cli.command_modules.rdbms', 'azext_rdbms_connect']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: rdbms 0.151 55 230
cli.azure.cli.core: Total (1) 0.151 55 230
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: rdbms-connect 0.373 4 4 /home/jmservera/.azure/cliextensions/rdbms-connect
cli.azure.cli.core: Total (1) 0.373 4 4
cli.azure.cli.core: Loaded 55 groups, 234 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : mysql flexible-server execute
cli.azure.cli.core: Command table: mysql flexible-server execute
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7faa3b6c6d40>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/jmservera/.azure/commands/2023-06-02.09-30-35.mysql_flexible-server_execute.1442.log'.
az_command_data_logger: command args: mysql flexible-server execute --admin-user {} --admin-password {} --name {} -f {} --database-name {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7faa3b6e3880>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7faa3b7417e0>, <function register_cache_arguments..add_cache_arguments at 0x7faa3b741900>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7faa3c820160>, <function CLIQuery.handle_query_parameter at 0x7faa3c851360>, <function register_ids_argument..parse_ids_arguments at 0x7faa3b741870>]
az_command_data_logger: extension name: rdbms-connect
az_command_data_logger: extension version: 1.0.4
cli.azext_rdbms_connect.custom: Running sql file '/tmp/test.sql'...
cli.azext_rdbms_connect.custom: Successfully executed the file.
cli.azext_rdbms_connect.custom: Closed the connection to airsdeleteme
cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x7faa3b70ad40>, <function _x509_from_base64_to_hex_transform at 0x7faa3b70add0>]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7faa3b6c6f80>]
az_command_data_logger: exit code: 0
cli.main: Command ran in 2.438 seconds (init: 0.228, invoke: 2.210)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 3552 in cache
telemetry.check: Negative: The /home/jmservera/.azure/telemetry.txt was modified at 2023-06-02 09:29:50, which in less than 600.000000 s

Expected behavior

The same result when using the --query option. It is already implemented there in line 201

# only print out if rows were returned
if cursor.description:
    result = cursor.fetchmany(30)  # limit to 30 rows of output for now
    row_headers = [x[0] for x in cursor.description]  # this will extract row headers
    # format the result for a clean display
    json_data = []
    for rv in result:
        json_data.append(dict(zip(row_headers, rv)))

using the command az mysql flexible-server execute --admin-user $CURRENT_USERNAME --admin-password "$TOKEN" --name $MYSQL_SERVER_NAME -q "SELECT 'HELLO WORLD';" --database-name 'airsonic' -o table shows:

Successfully connected to airsdeleteme.
Ran Database Query: 'SELECT 'HELLO WORLD';'
Retrieving first 30 rows of query output, if applicable.
Closed the connection to airsdeleteme
HELLO WORLD
-------------
HELLO WORLD

Environment Summary

azure-cli 2.49.0

core 2.49.0
telemetry 1.0.8

Extensions:
rdbms-connect 1.0.4

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/home/jmservera/.azure/cliextensions'

Python (Linux) 3.10.10 (main, May 19 2023, 08:20:31) [GCC 11.3.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

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

yonzhan commented Jun 2, 2023

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

@jsntcy jsntcy added MySQL Service Attention This issue is responsible by Azure service team. labels Jun 2, 2023
@ghost
Copy link

ghost commented Jun 2, 2023

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ambhatna, @savjani.

Issue Details

Describe the bug

When running the command az mysql flexible-server execute using the file input option -f query.sql, it does not show the output of the query as it does when using the query option -q "SELECT 'HELLO WORLD'" because the code that shows the output is not present in the _connect_execute_file method:

Related command

az mysql flexible-server execute

Errors

NAME -f /tmp/test.sql --database-name 'airsonic'
Running sql file '/tmp/test.sql'...
Successfully executed the file.
Closed the connection to airsdeleteme

Issue script & Debug output

cli.knack.cli: Command arguments: ['mysql', 'flexible-server', 'execute', '--admin-user', '', '--admin-password', '', '--name', 'airsdeleteme', '-f', '/tmp/test.sql', '--database-name', 'airsonic', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7faa3c90d480>, <function OutputProducer.on_global_arguments at 0x7faa3c8200d0>, <function CLIQuery.on_global_arguments at 0x7faa3c8512d0>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'mysql': ['azure.cli.command_modules.rdbms', 'azext_rdbms_connect']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: rdbms 0.151 55 230
cli.azure.cli.core: Total (1) 0.151 55 230
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: rdbms-connect 0.373 4 4 /home/jmservera/.azure/cliextensions/rdbms-connect
cli.azure.cli.core: Total (1) 0.373 4 4
cli.azure.cli.core: Loaded 55 groups, 234 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : mysql flexible-server execute
cli.azure.cli.core: Command table: mysql flexible-server execute
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7faa3b6c6d40>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/jmservera/.azure/commands/2023-06-02.09-30-35.mysql_flexible-server_execute.1442.log'.
az_command_data_logger: command args: mysql flexible-server execute --admin-user {} --admin-password {} --name {} -f {} --database-name {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7faa3b6e3880>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7faa3b7417e0>, <function register_cache_arguments..add_cache_arguments at 0x7faa3b741900>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7faa3c820160>, <function CLIQuery.handle_query_parameter at 0x7faa3c851360>, <function register_ids_argument..parse_ids_arguments at 0x7faa3b741870>]
az_command_data_logger: extension name: rdbms-connect
az_command_data_logger: extension version: 1.0.4
cli.azext_rdbms_connect.custom: Running sql file '/tmp/test.sql'...
cli.azext_rdbms_connect.custom: Successfully executed the file.
cli.azext_rdbms_connect.custom: Closed the connection to airsdeleteme
cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x7faa3b70ad40>, <function _x509_from_base64_to_hex_transform at 0x7faa3b70add0>]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7faa3b6c6f80>]
az_command_data_logger: exit code: 0
cli.main: Command ran in 2.438 seconds (init: 0.228, invoke: 2.210)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 3552 in cache
telemetry.check: Negative: The /home/jmservera/.azure/telemetry.txt was modified at 2023-06-02 09:29:50, which in less than 600.000000 s

Expected behavior

The same result when using the --query option. It is already implemented there in line 201

# only print out if rows were returned
if cursor.description:
    result = cursor.fetchmany(30)  # limit to 30 rows of output for now
    row_headers = [x[0] for x in cursor.description]  # this will extract row headers
    # format the result for a clean display
    json_data = []
    for rv in result:
        json_data.append(dict(zip(row_headers, rv)))

using the command az mysql flexible-server execute --admin-user $CURRENT_USERNAME --admin-password "$TOKEN" --name $MYSQL_SERVER_NAME -q "SELECT 'HELLO WORLD';" --database-name 'airsonic' -o table shows:

Successfully connected to airsdeleteme.
Ran Database Query: 'SELECT 'HELLO WORLD';'
Retrieving first 30 rows of query output, if applicable.
Closed the connection to airsdeleteme
HELLO WORLD
-------------
HELLO WORLD

Environment Summary

azure-cli 2.49.0

core 2.49.0
telemetry 1.0.8

Extensions:
rdbms-connect 1.0.4

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/home/jmservera/.azure/cliextensions'

Python (Linux) 3.10.10 (main, May 19 2023, 08:20:31) [GCC 11.3.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

Author: jmservera
Assignees: -
Labels:

bug, MySQL, Service Attention

Milestone: -

@savjani
Copy link

savjani commented Jun 2, 2023

Adding @mksuni to help with this

@mksuni
Copy link

mksuni commented Jun 5, 2023

Hi @jmservera, This is by design when executing from a script from a file to make it easier for automation scenarios with CLI. If there is any additional information you can provide that this is critical issue for you , please do share the details. This will help us evaluate based on your scenario.

@jmservera
Copy link
Author

Thanks @mksuni . In my scenario, I was running a script like this one for MySQL:

SET aad_auth_validate_oids_in_tenant = OFF;
DROP USER IF EXISTS 'myIdentity';
SELECT 'CREATING USER';
CREATE AADUSER 'myIdentity' IDENTIFIED BY '000-000-000';
SELECT 'GRANTING PRIVILEGES';
GRANT ALL PRIVILEGES ON airsonic.* TO 'myIdentity'@'%';
FLUSH privileges;

This script does not work when using a direct query (I don't know completely why, but the CREATE USER fails when), but it does work when running it from a file. My problem is that when running it from a GitHub Action, if I want to check the logs to see what happened I don't get any output from the execution, just a failure or a success.
I don't see why discarding the output makes it easier for anyone, I'm probably not seeing a scenario where having the output hurts, but if this is the case, I would prefer to have an optional parameter to show the output so I can configure when to show it instead of blindly debugging my scripts.

Thanks,
Juanma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. MySQL Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

5 participants